Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my script to change name of sign only work in studio and not in an actual game?

script.Parent.ClickDetector.MouseClick:connect(function()
	if script.Parent.SurfaceGui.TextLabel.Text == "______'s Creation Station" then
		local clicker = game.Players.LocalPlayer.Name
		script.Parent.SurfaceGui.TextLabel.Text = clicker.."'s Creation Station"
	elseif
		script.Parent.SurfaceGui.TextLabel.Text ~= "______'s Creation Station" then
		local gui = game.ServerStorage.alreadyClaimedGui:clone()
		gui.Parent = game.Players.LocalPlayer.PlayerGui
		gui.TextLabel:TweenPosition(UDim2.new(0.3,0,0.2,0), 'Out', 'Elastic', 2)
		wait(3)
		gui:Remove()
		
	end
end)

Script above is in a normal script, parent tree looks like game>workspace>signTop>clickToClaim(this script)

It works perfectly fine in studio test mode, but whenever I load into a test server or into a real server, it doesn't work and I can't figure out why.

6 comments

0

This is a roblox bug... Gui text changing with scripts messes it up for some reason I have the same issue with a leaderstat gui!

0

A roblox bug, as in there's no way for me to fix it myself?

0

I don't think it's a roblox bug,While playing your game open Developer Console(press F9) and goto server log, and say what error it's showing?

0

Workspace.signTop.clickToClaim:3: attempt to index a field 'LocalPlayer' (a nil value)

0

as far i think local scripts can't access ServerStorage.

0

wait is your script normal script?

1 answer

This isn't a ROBLOX bug. It has to do with FE and what scripts/localscripts have access to.

Server scripts cannot access the PlayerGui with FilteringEnabled; the same way LocalScripts can't access the ServerStorage

Also, normal scripts can't use LocalPlayer, which explains your error.

Use remote events.

Make a remote event in the ReplicatedStorage called "MakeAlreadyClaimedGui"

Put "alreadyClaimedGui" in ReplicatedStorage, not ServerStorage

Your Script

local claimed_re = game:GetService("ReplicatedStorage"):WaitForChild("MakeAlreadyClaimedGui")

script.Parent.ClickDetector.MouseClick:Connect(function(player) -- that comes with the event.
	if script.Parent.SurfaceGui.TextLabel.Text == "______'s Creation Station" then
		script.Parent.SurfaceGui.TextLabel.Text = clicker.."'s Creation Station"
	elseif
		script.Parent.SurfaceGui.TextLabel.Text ~= "______'s Creation Station" then
		claimed_re:FireClient(player)
	end
end)

LocalScript in StarterGui

local claimed_re = game:GetService("ReplicatedStorage"):WaitForChild("MakeAlreadyClaimedGui")

claimed_re.OnClientEvent:Connect(function()
	local gui = game:GetService("ReplicatedStorage").alreadyClaimedGui:Clone()
	gui.Parent = script.Parent
	gui.TextLabel:TweenPosition(UDim2.new(0.3,0,0.2,0), 'Out', 'Elastic', 2)
	wait(3)
	gui:Destroy()
end)

Also:

  1. connect is deprecated; use Connect
  2. clone is deprecated; use Clone
  3. Remove is deprecated; use Destroy()
  4. Normal scripts can't use LocalPlayer - that is for LocalScripts.

1 comment

0

Thank you so much :D it worked! Do you have a link to somewhere that can explain what's going on here? I dont really understand the changes you made

This discussion is preserved as it was. New answers, comments, and votes are closed.