Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago
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.

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! Voideyz 4 — 6y
0
A roblox bug, as in there's no way for me to fix it myself? DoctahBee 0 — 6y
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? TheSkyofIndia 150 — 6y
0
Workspace.signTop.clickToClaim:3: attempt to index a field 'LocalPlayer' (a nil value) DoctahBee 0 — 6y
View all comments (2 more)
0
as far i think local scripts can't access ServerStorage. TheSkyofIndia 150 — 6y
0
wait is your script normal script? TheSkyofIndia 150 — 6y

1 answer

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago
Edited 6 years ago

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.
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 DoctahBee 0 — 6y
Ad

Answer this question