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)
You're doing something really wrong here. The reason this worked in solo is because everything is ran locally there, meaning you're not testing the server.
For the Touched event, this is ran in the server, meaning you cannot assign it to a local script rather use a server script.
You cannot use LocalPlayer in a serverscript.
Solution:
script.Parent.Touched:connect(function(hit) local air=1 if hit.Name == "Head" then local plr - game.Players:GetPlayerFromCharacter(hit.Parent) if plr then plr.PlayerGui.Waterblur.Frame.Visible = true plr.PlayerGui.Drown.Frame.Visible = true while wait(.1) do air = air - 0.01 plr.PlayerGui.Drown.Frame.TextLabel.Size = UDim2.new(air, 0, 1, 0) if plr.PlayerGui.Drown.Frame.Visible == false then plr.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 plr.PlayerGui.Drown.Frame.Visible == false break end end end end end) script.Parent.TouchEnded:connect(function(hit) if hit.Name == "Head" then local plr - game.Players:GetPlayerFromCharacter(hit.Parent) if plr then plr.PlayerGui.Waterblur.Frame.Visible = false plr.PlayerGui.Drown.Frame.Visible = false end end end)
The problem is that you're using "LocalPlayer" on a script whose ancestor is the Workspace. That means that this script is treated like a server script. Even if you've made this a LocalScript, it won't run.
You have two options:
You can simply make this a LocalScript, put it inside game.StarterGui, and change the first line to be "game.Workspace.Water.Touched" (or whatever the path to your part is).
Split the script into a server-side script and a client-side script. The server would be responsible for telling the client when the client enters and leaves water, and also for telling the client how much air is left. The client would just be responsible for updating the gui. You would need to use RemoteEvents to transmit this information.