Hi, I was making this script where when you touched this part it would damage you for 5 seconds and it would change the text on the textlabel to say status: poison. But my script wont change the text. Can you help?
Textlabel script:
local plr = Game.Players.LocalPlayer repeat wait() until plr local status = Instance.new("StringValue",plr) status.Name = "status-"..plr.UserId repeat wait() until plr:WaitForChild("status") while true do wait() script.Parent.Text = "Effects: "..plr.status.Value end
Brick touched script:
local no = false local plr = Game.Players.LocalPlayer repeat wait() until plr script.Parent.Touched:connect(function(part) if not no then no = true local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then plr.status.Value = "Poison" for time = 5,0,-1 do humanoid.Health = humanoid.Health - 5 wait(1) end wait(2) no = false end end end)
Can you try to help me with my script?
1.
Don't bother with the status.Name = "bleh-" .. stuffhere, just do "status" (in your first script).
2.
This is all the second script:
local no = false local plr = Game.Players.LocalPlayer repeat wait() until plr.Character local char = plr.Character script.Parent.Touched:connect(function(part) if no == false then no = true local humanoid = char:WaitForChild("Humanoid") plr.status.Value = "Poison" local num = 5 while num > 0 do -- alternative, and better way for your script to take away health humanoid.Health = humanoid.Health - 5 num = num - 1 wait(1) end wait(2) no = false end end)
Hope you don't mind if I re-write your scripts but here you go:
TextLable LocalScript:
local plr = Game.Players.LocalPlayer status=plr:WaitForChild("status") status.Changed:connnect(function() script.Parent.Text = "Effects: "..plr.status.Value end)
Extra Player Added Script:
game.Players.PlayerAdded:connect(function(player) stat=Instance.new("StringValue", player) stat.Name="status" end)
BrickTouched Script:
derp=false script.Parent.Touched:connect(function(part) if derp==false then hum=part.Parent:FindFirstChild("Humanoid") if hum then plr=game.Players:GetPlayerFromCharacter(part.Parent) if plr then derp=true status=plr:FindFirstChld("status") if status then status.Value="Poisoned" else print("Status not found, creating one") status=Instance.new("StringValue", plr) status.Name="status" status.Value="Poisoned" end for time = 5,0,-1 do hum.Health = hum.Health - 5 wait(1) end wait(2) derp=false end end end)
That should do it, you made a good attempt but there were several things wrong and some not needed parts. You can't access a LocalPlayer from a regular script and there is no point on putting a .Touched local script in a brick that can be touched by anyone. I made a PlayerAdded script because server scripts can't mess with things that are made by clients if you have FilteringEnabled. Just in case that didn't work, the .Touched event would put a status in the player if one was not found. A .Changed even is more efficient in this situation as it runs if a property has changed, not in a while loop which takes up processing power. A :WaitForChild() function will wait for a child, it doesn't need to have a repeat wait() until. I hope this helped.