Water touched script wont work

Hi i have a problem with a touched part heres what the problem is
it doesnt show errors but still wont work the gui wont show up

script.Parent.Touched:Connect(function()
	game.startergui.Water.Enabled = true
end)
1 Like

Is CanTouch on in the properties of the part?

1 Like

You’re changing the starterGui, not the player’s playerGui.

1 Like

how do i acess the player gui since idk where it is

yes cantouch is on i checked the properties

1 Like

You’ll need to check if the thing that touched the part is a player. Then check who is the player that touched it.

local Players = game:GetService("Players")
 
local part = script.Parent
local function onTouched(part)
	local player = Players:GetPlayerFromCharacter(part.Parent)
	if not player then return end
	player.PlayerGui:WaitForChild("Water").Enabled = true
end
part.Touched:Connect(onTouched)

And then you can change the player’s PlayerGui.

3 Likes

You need to update the PlayerGui of the player who touched it. Not StarterGui.

1 Like

i tried doing it but nothing is happening

local ScreenGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("Water")

script.Parent.Touched:Connect(function()
ScreenGui.Enabled = true
end)

1 Like

Sorry made a mistake. I’m editing my script.
It should work now

2 Likes

You can’t use local player in a server script

Instead check if hit.Parent is a player/character:

local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
    local water = plr.PlayerGui:FindFirstChild("Water")
end

Put this in the touched event

this is confusing i dont know where you mean i should put the player gui script like

Changing the StarterGui does not change the Player’s PlayerGui. I assumed your script is a Server Script.

What the script that I wrote does is it checks if a player is the one touching the part, and then gets that player’s PlayerGui and enables the ScreenGui.

no it is in the part that i want touched

You need to use player GUI because everything gets cloned from starter GUI to player GUI when player joins so after that everything you do to the starter GUI the player won’t see since he sees a different gui

i tried it im not sure im trying to see if the script is wrong or not

So, what you want is to make a player’s GUI visible whenever a player touches a part right?

Put this script in your part

script.Parent.Touched:Connect(function(hit)
     local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
     if plr then
        local water = plr.PlayerGui:FindFirstChild("Water")
        water.Enabled = true
    end
end)
2 Likes

yes and thats the problem it gets touched nothing shows

Well that’s because:

  1. You are changing the StarterGui. Not a player’s PlayerGui. If you don’t understand, Every time a player joins, Everything in the StarterGui gets replicated to the Player’s PlayerGui.
    In short, a PlayerGui and a StarterGui aren’t the same thing.

  2. You aren’t checking if the thing that touched the part is a player in the first place.

  3. You aren’t checking who is the player that touched the part.