Can I Use This Code Again?

Hi, so I have this code to make a gui appear when a player touches a part.

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
	game.ReplicatedStorage.RemoteEvent:FireClient(plr)
    end
end)

However I want to make a different gui appear when a player touches a different part so how would I change this code?

Use a different RemoteEvent for another Gui.

1 Like

This could work as well but rather than making a lot of RemoteEvents I suggest adding a second argument what to open

--Shop
script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
	game.ReplicatedStorage.RemoteEvent:FireClient(plr,"Shop")
    end
end)
--Setings
script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
	game.ReplicatedStorage.RemoteEvent:FireClient(plr,"Settings")
    end
end)
1 Like

Instead of using remotes at all, you can just have the client detect touches against a part, verify it’s the current client then open a Gui based on what part was touched. There’s no need to be crossing the client-server boundary here at all.

1 Like

@Play_MazeOfHeck,i didnt understand too much,can you explain better?

Alvin Blox made a whole video about this. I suggest checking it out: