kyupita Posted February 1 Share Posted February 1 I'm trying to add a glow to an object and I'm using code from the lightbulbs. However, the game crashes at the part where it's setting up the light, giving me the message "attempt to index field 'Light' (a nil value)." local function OnDropped(inst) inst.Light:Enable(true) end local function OnPutInInventory(inst) inst.Light:Enable(false) end local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("dnadata") inst.AnimState:SetBuild("dnadata") inst.AnimState:PlayAnimation("idle") inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh") inst.Light:SetIntensity(.8) -- Games crashes here inst.Light:SetRadius(0) inst.Light:SetFalloff(.5) inst.Light:SetColour(169 / 255, 231 / 255, 245 / 255) inst.Light:Enable(true) inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end Link to comment https://forums.kleientertainment.com/forums/topic/169691-attempt-to-index-field-light-a-nil-value/ Share on other sites More sharing options...
Meepenator Posted February 1 Share Posted February 1 inst.entity:AddLight() Isn't there so it's pulling up nil 1 Link to comment https://forums.kleientertainment.com/forums/topic/169691-attempt-to-index-field-light-a-nil-value/#findComment-1850456 Share on other sites More sharing options...
kyupita Posted February 1 Author Share Posted February 1 1 hour ago, Meepenator said: inst.entity:AddLight() Isn't there so it's pulling up nil I completely missed that....... 😭 Thank you very much! I have another issue though with something else though, I'm trying to rework how my character's light works and wanted to make it so that when his hunger gets low, the light he gives off gets weaker. This was how it initially worked before i decided to rework it: -- Located above master postinit local function anglerLight(inst) inst.Light:SetIntensity(.7) inst.Light:SetRadius(4) inst.Light:SetFalloff(.75) inst.Light:SetColour(235 / 255, 165 / 255, 12 / 255) inst.Light:Enable(true) end However, this code is making my game crash right now: -- Inside master postinit function anglerLightFull(inst) -- Error message here inst.Light:SetIntensity(.7) inst.Light:SetRadius(4) inst.Light:SetFalloff(.75) inst.Light:SetColour(235 / 255, 165 / 255, 12 / 255) inst.Light:Enable(true) end function anglerLightMed(inst) inst.Light:SetIntensity(.5) inst.Light:SetRadius(3) inst.Light:SetFalloff(.75) inst.Light:SetColour(235 / 255, 165 / 255, 12 / 255) inst.Light:Enable(true) end function anglerLightLow(inst) inst.Light:SetIntensity(.3) inst.Light:SetRadius(2) inst.Light:SetFalloff(.75) inst.Light:SetColour(235 / 255, 165 / 255, 12 / 255) inst.Light:Enable(true) end function anglerLightOff(inst) inst.Light:Enable(false) end local HungerPercent = inst.components.hunger:GetPercent() if HungerPercent >= .75 then anglerLightFull() elseif HungerPercent >= .5 and HungerPercent < .75 then anglerLightMed() elseif HungerPercent >= .25 and HungerPercent < .5 then anglerLightLow() elseif HungerPercent < .25 then anglerLightOff() end -- Listen for when player respawns inst:ListenForEvent("ms_respawnedfromghost", anglerLightFull) I'm currently getting the error "assign to undeclared variable 'anglerLightFull'" Before it kept crashing due to "inst" not being declared Link to comment https://forums.kleientertainment.com/forums/topic/169691-attempt-to-index-field-light-a-nil-value/#findComment-1850467 Share on other sites More sharing options...
Meepenator Posted February 2 Share Posted February 2 crocodile.lua local function LocalHunger (inst, data) local currenthunger = inst.components.hunger.current if inst.components.hunger.current > 0 then inst.Light:Enable(true) inst.Light:SetRadius(math.min(math.max(0,3 * ((currenthunger ) / 75) ),3)) inst.Light:SetFalloff(1) inst.Light:SetIntensity(0.5) inst.Light:SetColour(240/232,232/104,104/255) else inst.Light:Enable(false) end end inst:ListenForEvent("hungerdelta", LocalHunger) Get rid of all that and use this code I made for another character like 7 years ago. It basically gradually turns down your light as your hunger goes and disappears when you hit 0. 1 Link to comment https://forums.kleientertainment.com/forums/topic/169691-attempt-to-index-field-light-a-nil-value/#findComment-1850468 Share on other sites More sharing options...
kyupita Posted February 2 Author Share Posted February 2 omg THANK YOU!!!!!!! You've helped me greatly, I really appreciate it!! ^^ Link to comment https://forums.kleientertainment.com/forums/topic/169691-attempt-to-index-field-light-a-nil-value/#findComment-1850470 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