Sacco Posted September 10, 2024 Share Posted September 10, 2024 So, i was trying to give Wolfgang a higher sanity drain the lower his sanity is. local function onsanitychange(inst, data) local sanityboost = 1 if inst.components.sanity:GetPercent()<0.50 then sanityboost = 1.5 end end GLOBAL.TUNING.WOLFGANG_SANITY_NIGHT_DRAIN = 1.25 * sanityboost AddPrefabPostInit("wolfgang", function(inst) if GLOBAL.TheWorld.ismastersim then inst:ListenForEvent("sanitydelta", onsanitychange) end end) But when i try to load a world this error shows up: attempt to perform arithmetic on global 'sanityboost' (a nil value) I don't understand the reason, can someone explain why and help me fix it? Thanks! Link to comment https://forums.kleientertainment.com/forums/topic/159607-why-is-this-thing-a-nil-value/ Share on other sites More sharing options...
Baguettes Posted September 10, 2024 Share Posted September 10, 2024 You defined sanityboost inside a function, and it'd only work within that function! D: Either you move the global tuning into the onsanitychange function, or you move the local sanityboost out of there for it to work. 1 Link to comment https://forums.kleientertainment.com/forums/topic/159607-why-is-this-thing-a-nil-value/#findComment-1746910 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now