local cop = game.ServerStorage.Fgt
local p = 0
local function onClicked(hit)
p = 1
hit.PlayerGui.ScreenGui.ThreatLevel.Text = "Caution!"
cop.Parent = game.Workspace
wait(8)
hit.PlayerGui.ScreenGui.ThreatLevel.Text = "No Threat"
end
game.Workspace.fgtbutton.ClickDetector.MouseClick:connect(onClicked)
if p == 1
then
while true do
if game.workspace.Fgt.Humanoid.Health <100
then
game.workspace.Fgt.Humanoid.Health = 100
game.workspace.Fgt.Parent = game.ServerStorage
end
end
That is my problem it doesn't move it or heal it ?
I think the problem lays in the "while true do" part but I am a beginner scripter, so I need help to figure why it does this ?
Try this:
local cop = game.ServerStorage.Fgt local p = 0 game.Workspace.fgtbutton.ClickDetector.MouseClick:connect(function(hit) plr = hit.Parent.Name -- name of person who hit the button p = 1 game.Players:FindFirstChild(plr).PlayerGui.ScreenGui.ThreatLevel.Text = "Caution!" cop.Parent = game.Workspace wait(8) game.Players:FindFirstChild(plr).PlayerGui.ScreenGui.ThreatLevel.Text = "No Threat" end) while true do -- do a loop to check constantly wait() -- add a wait in the loop so it doesnt crash if p == 1 then if game.workspace:FindFirstChild('Fgt') then -- add an extra check to make sure he exists if game.workspace:FindFirstChild('Fgt'):FindFirstChild('Humanoid').Health <100 then -- we use findfirstchild incase he is not in workspace; some error happens. game.workspace.Fgt.Humanoid.Health = 100 game.workspace.Fgt.Parent = game.ServerStorage end end end end
Thanks your script around finding out how spawned him was over complicated
local cop = game.ServerStorage.Fgt local p = 0 local function onClicked(hit) p = 1 hit.PlayerGui.ScreenGui.ThreatLevel.Text = "Caution!" cop.Parent = game.Workspace wait(8) hit.PlayerGui.ScreenGui.ThreatLevel.Text = "No Threat" end game.Workspace.fgtbutton.ClickDetector.MouseClick:connect(onClicked) while true do -- do a loop to check constantly wait() if p == 1 then if game.workspace:FindFirstChild('Fgt') then if game.workspace:FindFirstChild('Fgt'):FindFirstChild('Humanoid').Health <100 then game.workspace.Fgt.Humanoid.Health = 100 game.workspace.Fgt.Parent = game.ServerStorage end end end end -- credit to killerkill29 for helping me with the script loop.