LocalScript Firing for Server Instead of Local Player

  1. What do you want to achieve? Keep it simple and clear!
    I would like for the GUI to pop up without it firing for the whole server.

  2. What is the issue? Include screenshots / videos if possible!
    The GUI pops up for the whole server, even though it’s in a LocalScript. Here’s a video of that happening:
    2022-07-03 12-41-45

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Can’t find any solutions, however I believe it’s due to the LocalScript detecting if a part has been touched.

Here is my code:

local TextLabel = script.Parent.MainFrame.TextLabel
local Ready = true

for _, v in pairs(workspace.TutorialParts:GetChildren()) do
	v.Touched:Connect(function(Hit)
		if v ~= nil then
			if v.Parent == workspace.TutorialParts then
				local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
				if Player then
					local TutorialText = v:FindFirstChild("Text")
					if Ready then
						Ready = false
						script.Parent.MainFrame:TweenPosition(UDim2.new(0.5,0, 0.84,0), "Out", "Bounce", 1.5, true)
						wait(1.5)
						local function Typewrite(Object,Text)
							for i = 1,#Text,1 do
							Object.Text = string.sub(Text,1,i)
							wait(0.05)
							end
						end
						
						Typewrite(TextLabel," "..TutorialText.Value)
						wait(2)
						script.Parent.MainFrame:TweenPosition(UDim2.new(0.5,0, 1.42,0), "Out", "Bounce", 1.5, true)
						TextLabel.Text = ""
						Ready = true
					end
				end
			end
		end
	end)
end

You have to declare the PlayerGui in your script.

Also, make this a server script inside the part.

1 Like

Take a look at these lines:

local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
				if Player then
					local TutorialText = v:FindFirstChild("Text")
					if Ready then
						Ready = false
						script.Parent.MainFrame:TweenPosition(UDim2.new(0.5,0, 0.84,0), "Out", "Bounce", 1.5, true)

You’re saying that every time any player hits the part, it tweens whatever frame the script is a child of. So if this frame is in StarterGui with the localscript, and I see someone touch the part, the tween will activate for everyone.

Instead of:

script.Parent.MainFrame:TweenPosition(UDim2.new(0.5,0, 0.84,0), "Out", "Bounce", 1.5, true)

specify the frame specific to that player’s gui using Player.PlayerGui, not “script.Parent”. You also need to keep it as a localscript.

2 Likes