Ad
Log in to vote
1

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

Asked by 8 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:

script.Parent.Parent:WaitForChild("Humanoid").Died:connect(function()
    script.Parent.Parent.Torso.BrickColor = BrickColor.new("Really black")
    script.Parent.Parent["Left Arm"].BrickColor = BrickColor.new("Really black")
    script.Parent.Parent["Left Leg"].BrickColor = BrickColor.new("Really black")
    script.Parent.Parent["Right Arm"].BrickColor = BrickColor.new("Really black")
    script.Parent.Parent["Right Leg"].BrickColor = BrickColor.new("Really black")
    script.Parent.Parent.Monster:Destroy()
    script.Parent.Roar:Play()
    wait(1.5)
    game.Workspace.Crumble:Play()
    script.Parent.Parent.Torso.Fire.Enabled = false
    script.Parent.Parent.Torso.Smoke.Enabled = true
    wait(4)
    script.Parent.Parent.Torso.Smoke.Enabled = false




end)


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 8 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;

function 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
repeat wait() until str:FindFirstChild(obj) --This will repeat until the code finds 'obj' within 'str'
return str:FindFirstChild(obj) --This will return 'obj' when it is found
end --This ends the code block for the function

local Figure = script.Parent.Parent --Figure is the Script's Parent's Parent
local Torso = WaitForChild(Figure,"Torso") --This will repeat until 'Torso' is existant within 'Figure', and will return it
local LeftArm = WaitForChild(Figure,"Left Arm") --This will repeat until 'Left Arm' is existant within 'Figure', and will return it
local RightArm = WaitForChild(Figure,"Right Arm") --This will repeat until 'Right Arm' is existant within 'Figure', and will return it
local LeftLeg = WaitForChild(Figure,"Left Leg") --This will repeat until 'Left Leg' is existant within 'Figure', and will return it
local RightLeg = WaitForChild(Figure,"Right Leg") --This will repeat until 'Right Leg' is existant within 'Figure', and will return it
local Humanoid = WaitForChild(Figure,"Humanoid") --This will repeat until 'Humanoid' is existant within 'Figure', and will return it
WaitForChild(script.Parent,"Roar") --This will repeat until 'Roar' is existant within the Script's Parent
WaitForChild(Figure,"Monster") --This will repeat until 'Monster' is existant within 'Figure'
WaitForChild(game.Workspace,"Crumble") --This will repeat until 'Crumble' is existant within 'game.Workspace'
WaitForChild(Torso,"Fire") --This will repeat until 'Fire' is existant within 'Torso'
WaitForChild(Torso,"Smoke") --This will repeat until 'Smoke' is existant within 'Torso'

Humanoid.Died:connect(function() --This will fire when the Humanoid dies
Torso.BrickColor = BrickColor.new("Really black") --This will turn 'Torso''s BrickColor to 'Really black'
LeftArm.BrickColor = BrickColor.new("Really black") --So on
LeftLeg.BrickColor = BrickColor.new("Really black") --So on
RightArm.BrickColor = BrickColor.new("Really black") --So on
RightLeg.BrickColor = BrickColor.new("Really black") --And so on
Figure.Monster:Destroy() --This will destroy 'Monster' within 'Figure'
script.Parent.Roar:Play() --This will play the 'Sound' 'Roar'
wait(1.5) --Will wait '1.5' seconds [One and a half]
game.Workspace.Crumble:Play() --Will play the 'Sound' 'Crumble'
Torso.Fire.Enabled = false --This will disable the 'Fire' type instance within 'Torso'
Torso.Smoke.Enabled = true --This will enable the 'Smoke' type instance within 'Torso'
wait(4) --Will wait '4' seconds
Torso.Smoke.Enabled = false --This will disable the 'Smoke' type instance within 'Torso'
end) --This ends the code block for the Function/Event

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 — 8y
Ad
Log in to vote
-4
Answered by 8 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 — 8y
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 — 8y
0
Instead of script.Parent.Parent:WaitForChild("Humanoid").Died:connect(function() try game.Players.LocalPlayer:WaitForChild("Humanoid").Died:connect(function() SprocketSoldier 0 — 8y
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 — 8y