Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Script works in 'Run' but not 'Play Solo'? [ANSWERED] [closed]

Asked by 10 years ago

So I have a script inside of a Monster NPC that does stuff when it dies. (it's health get lowered when it touches a block called 'IceCube'. It worked in a different place, and when I tried it out in 'Run' mode it also worked. I even named a part 'IceCube' and killed him with that and everything worked

Then when I went to 'play solo' and used the water bucket, It still did damage and killed him, it's just the script didn't work

2 errors came up only on 'play solo':

17:17:16.946 - Torso is not a valid member of Part 17:17:16.947 - Script 'Workspace.Lava Monster.Head.DeathSound', Line 3 17:17:16.948 - Stack End 17:17:16.948 - Disconnected event because of exception 17:17:18.134 - Humanoid is not a valid member of Model 17:17:18.135 - Script 'Workspace.Lava Monster.Monster', Line 41 17:17:18.135 - Stack End

Here's the script:

01script.Parent.Parent:WaitForChild("Humanoid").Died:connect(function()
02    script.Parent.Parent.Torso.BrickColor = BrickColor.new("Really black")
03    script.Parent.Parent["Left Arm"].BrickColor = BrickColor.new("Really black")
04    script.Parent.Parent["Left Leg"].BrickColor = BrickColor.new("Really black")
05    script.Parent.Parent["Right Arm"].BrickColor = BrickColor.new("Really black")
06    script.Parent.Parent["Right Leg"].BrickColor = BrickColor.new("Really black")
07    script.Parent.Parent.Monster:Destroy()
08    script.Parent.Roar:Play()
09    wait(1.5)
10    game.Workspace.Crumble:Play()
11    script.Parent.Parent.Torso.Fire.Enabled = false
12    script.Parent.Parent.Torso.Smoke.Enabled = true
13    wait(4)
14    script.Parent.Parent.Torso.Smoke.Enabled = false
15 
16 
17 
18 
19end)

Locked by TheMyrco

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
1
Answered by 10 years ago

The problem is that Torso, and Humanoid has not loaded yet, so when the script fired, it did not find Torso or Humanoid, I have remade your script with some-what explanations, you could simply use the WaitForChild method [Which I did not use but should've :P], and that would've waited until the Torso and Humanoid have loaded;

01function WaitForChild(str,obj) --I have created a new function for you; this will help to wait for the Child; not necesary, could've simply used 'str:WaitForChild(obj)', but eh :P
02repeat wait() until str:FindFirstChild(obj) --This will repeat until the code finds 'obj' within 'str'
03return str:FindFirstChild(obj) --This will return 'obj' when it is found
04end --This ends the code block for the function
05 
06local Figure = script.Parent.Parent --Figure is the Script's Parent's Parent
07local Torso = WaitForChild(Figure,"Torso") --This will repeat until 'Torso' is existant within 'Figure', and will return it
08local LeftArm = WaitForChild(Figure,"Left Arm") --This will repeat until 'Left Arm' is existant within 'Figure', and will return it
09local RightArm = WaitForChild(Figure,"Right Arm") --This will repeat until 'Right Arm' is existant within 'Figure', and will return it
10local LeftLeg = WaitForChild(Figure,"Left Leg") --This will repeat until 'Left Leg' is existant within 'Figure', and will return it
11local RightLeg = WaitForChild(Figure,"Right Leg") --This will repeat until 'Right Leg' is existant within 'Figure', and will return it
12local Humanoid = WaitForChild(Figure,"Humanoid") --This will repeat until 'Humanoid' is existant within 'Figure', and will return it
13WaitForChild(script.Parent,"Roar") --This will repeat until 'Roar' is existant within the Script's Parent
14WaitForChild(Figure,"Monster") --This will repeat until 'Monster' is existant within 'Figure'
15WaitForChild(game.Workspace,"Crumble") --This will repeat until 'Crumble' is existant within 'game.Workspace'
View all 33 lines...

Hope this helped!

0
Thank you so much! I've been working on this update for the past 3 days and It's finally coming to a close thanks to you! I was about to say "I don't think that's the problem because I removed the ragdoll script and it worked (then the same error happened again :P) but now I realize what that error message means and I can learn from this greatly! Thanks! SpazzMan502 133 — 10y
Ad
Log in to vote
-4
Answered by 10 years ago

Yeah I have scripts that won't work in solo either.Your best bet is just to play your game to test it.

2
That's not an answer.... You must be new here. This isn't like Roblox forums where you comment whatever. SpazzMan502 133 — 10y
0
Ok, well I apologize sir. There is no way to fix your problem. Sorry for suggesting to you a solution. Have a great day crab. SprocketSoldier 0 — 10y
0
Instead of script.Parent.Parent:WaitForChild("Humanoid").Died:connect(function() try game.Players.LocalPlayer:WaitForChild("Humanoid").Died:connect(function() SprocketSoldier 0 — 10y
0
2 Things - Read the question thoroughly, I was talking about a humanoid in a monster, not the local player. Also, don't be rude in Scripting Helpers. I joined yesterday but I at least know some rules SpazzMan502 133 — 10y