UI Appearing For Everybody

Hello everyone, I am trying to make a ui appear for only the person that touched a certain part. However, when the player touches that part, the ui appears for everybody.
This is where the localscript is.
image
This is what is inside the ChefController localscript

local textLabel = script.Parent:WaitForChild("ChefSpeech") -- get the text label
local chef = script.Parent:WaitForChild("Chef") -- get the chef image
local text = textLabel.Text -- get the text that will be displayed on the text label
local isIntroFinished = Instance.new("BoolValue") -- create the boolvalue
isIntroFinished.Parent = script.Parent
isIntroFinished.Value = false
isIntroFinished.Name = "isIntroFinished"
local tomatoCan = game.Workspace:WaitForChild("TomatoCan") -- get the tomato can
local ranOnce = false


local function typewrite(object, text)
	chef.Visible = true
	textLabel.Visible = true
	textLabel.Text = ""
	for i = 1, #text, 1 do
		object.Text = string.sub(text, 1, i)
		wait(0.02)
	end
	wait(2)
	chef.Visible = false
	textLabel.Visible =  false
	print("set isintrofinished to true")
	isIntroFinished.Value = true
end

tomatoCan.Touched:Connect(function(touched)
	if touched.Parent:FindFirstChild("Humanoid") then
		if not ranOnce then
			typewrite(textLabel, text)
			ranOnce = true
		end
		
	end
end)

I am creating a boolvalue from the localscript and activating it, when the intro is finished, because I have another local script that checks if the boolvalue is activated, and makes the UI visible.

This is the contents of the other local script

local isIntroFinished = script.Parent.Parent:WaitForChild("isIntroFinished")
while isIntroFinished.Value == false do
	print("isIntrofinished is not finished")
	wait()
end

I read these these two threads but I didn’t understand ^

Thanks :slight_smile:

1 Like

The problem is that the .Touched triggers for everyone. Make sure that the one that touched it, is the local player! :P.

Here, change this line:

to:

if touched.Parent:FindFirstChild("Humanoid") and game.Players.LocalPlayer.Name == touched.Parent.Name then
1 Like

Thanks for the fast reply! I tried it out, it works :smiley:

I would recommend checking in this way:

part.Touched:connect(function(hit)
    local char = hit.Parent
    local player = game.Players:GetPlayerFromCharacter(char)
    if game.Players.LocalPlayer == player then
    -- do your thing
    end
end)
2 Likes

I would also reccomend doing it BoogaBoogaGuy’s way, its a bit more trustworthy

1 Like

alright, Thanks guys! I will do it that way