GUI meant for client shows for all players

  1. Hi, my intention is for the text label Gui to only show for the player whom collides with the part (in this instance, for the player wearing a “Skull”) however it shows for all players.

  2. https://gyazo.com/c9a8d482f6839f1ba1d9c352fc6a1a53

-- Local Script in the text label.

local Block = workspace.RespawnWarning
local plr = game.Players.LocalPlayer;
local ui = script.Parent;

Block.Touched:connect(function(Part)
	local Character = Part.Parent

	if Character == nil or Character:findFirstChild("Humanoid") == nil then return end

	local Head = Character:findFirstChild("Skull")

	if Head == nil then return end

	ui.Visible = true; 
	wait(5)
	ui.Visible = false;
end)

Is it a local script? A normal script will show for all players. While a local script only shows for the one person.

Yes, it’s a local script.

(char limit)

Maybe the script isn’t specific enough. All the players are listed during the game and they all are characters. Maybe you make it check the players name or something. Sorry if i sound dumb I’m a noob at scripting.

.Touched will trigger for any part that hits it (including other players characters), regardless of whether its local or not. A simple fix since you’re doing this locally is to check if the player that hit the part == the local player.

Just do something like:

local PS = game:GetService("Players");
local HitPlayer = PS:GetPlayerFromCharacter(Part.Parent);

if HitPlayer == PS.LocalPlayer then
-- continue logic
end;

Might be typos so watchout

You must do this in a server script. Local scripts doesn’t help, you’ll also need remote events.

Wait never mind, its local script

Bump. (I’ve tried doing a singular client remote event to no avail)

-- Script in part

local player = game:GetService("Players").LocalPlayer
local remoteEvent = game.ReplicatedStorage.RemoteEvent
script.Parent.Touched:Connect(function()
	remoteEvent:FireClient(player) -- :FireAllClients, it will show. Currently it does nothing.
end)

-- Local Script in text label
local ui = script.Parent;

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
	ui.Visible = true
end)

Perhaps its because when the block touches, it will fire for ALL players

Consider adding a condition statement checking if Part.Parent.Name==plr.Name then do the contents

else return.

As a side note, I suggest using zoneplusv2 module for more efficiency and utility but your choice:

2 Likes

Thank you, I’ll give this a shot.