burgelkat Posted September 26, 2021 Share Posted September 26, 2021 Hallo, i hope someone can explain this to me. i build a vwep praefab (like autogun) this script function and the bucket is show in the Start function i have this code. if i take the bucket, the child is now hidden. function Script:Start() local child = self.entity:FindChild("WaterforBucket") child:Hide() the problem now is, if i would show it again, i got an error. this is the code for showing the child function Script:becomewater()--in self.becomewater=true local child = self.entity:FindChild("WaterforBucket") if child:Hidden() then child:Show() end end the child is now nil. (Script Error attempt to index local "child" (a nil value) why now the child is not found? can someone explain and how i can fix it? Quote Link to comment Share on other sites More sharing options...
reepblue Posted September 26, 2021 Share Posted September 26, 2021 Since you can find the child on Start, I would store it in a variable to quick and easy access. I'd also put in null checks. Script.vmodel = nil function Script:Start() local child = self.entity:FindChild("WaterforBucket") if child ~= nil then self.vmodel = child self.vvmodel:Hide() end end function Script:DoSomething() -- Get my view model! local vm = self.vmodel vm:SetColor(1,0,0,1) end Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
burgelkat Posted September 26, 2021 Author Share Posted September 26, 2021 thanks for your answer. i got the first part. but at the "DoSomething" it crashs to desktop without error Quote Link to comment Share on other sites More sharing options...
reepblue Posted September 26, 2021 Share Posted September 26, 2021 It's probably a syntax error because It's just proto code, The point I was trying so show that you can store pointers into variables for easy access. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
burgelkat Posted September 26, 2021 Author Share Posted September 26, 2021 ah ok got it.. thanks .. i try .. and post again if it function. many thanks Quote Link to comment Share on other sites More sharing options...
burgelkat Posted September 27, 2021 Author Share Posted September 27, 2021 ok, solved it. In the player script I have to make a reference to the weapon index in order to trigger the function. self.weapons[self.currentweaponindex]:becomewater() Quote Link to comment Share on other sites More sharing options...
Marcousik Posted September 27, 2021 Share Posted September 27, 2021 Quote the problem now is, if i would show it again, i got an error. this is the code for showing the child function Script:becomewater()--in self.becomewater=true local child = self.entity:FindChild("WaterforBucket") if child:Hidden() then child:Show() end end the child is now nil. (Script Error attempt to index local "child" (a nil value) why now the child is not found? This is still a good question... Maybe it depends on where do you call the becomewater() function from ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.