Finished making a 'drowning' script that runs when your head is inside this brick, and makes a 'waterblur' Gui visible that basically puts a blue tint on your screen like you're underwater and another Gui pops up that is your air meter, and when it runs out you slowly start taking damage. When I run the script in Play Solo it works perfectly, but when I start a server and test it out, it doesn't work, and there isn't any errors in the output. Here is the script:
script.Parent.Touched:connect(function(hit)
local air=1
if hit.Name == "Head" then
game.Players.LocalPlayer.PlayerGui.Waterblur.Frame.Visible = true
game.Players.LocalPlayer.PlayerGui.Drown.Frame.Visible = true
while wait(.1) do
air = air - 0.01
game.Players.LocalPlayer.PlayerGui.Drown.Frame.TextLabel.Size = UDim2.new(air, 0, 1, 0)
if game.Players.LocalPlayer.PlayerGui.Drown.Frame.Visible == false then
game.Players.LocalPlayer.PlayerGui.Drown.Frame.TextLabel.Size = UDim2.new(1, 0, 1, 0)
break
end
if air <= 0 then
repeat
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10
wait(1)
until hit.Parent.Humanoid.Health == 0 or game.Players.LocalPlayer.PlayerGui.Drown.Frame.Visible == false
break
end
end
end
end)
script.Parent.TouchEnded:connect(function(hit)
if hit.Name == "Head" then
game.Players.LocalPlayer.PlayerGui.Waterblur.Frame.Visible = false
game.Players.LocalPlayer.PlayerGui.Drown.Frame.Visible = false
end
end)

1 comment
Alright, it worked. I see my mistake, sorry about that still a little new to the whole local/server thing :P. So basically in a local script you would want to get the player using LocalPlayer and in a server script use GetPlayerFromCharacter?