Info: I am working on an Airport Check-in System, and when you click the ImageButton in the GUI Frame, it doesn't hand you the ticket from ServerStorage. Error is listed below under "Output".
Output: > EC is not a valid member of ServerStorage
Local Script in ImageButton:
local player = game.Players.LocalPlayer local tool = game.ServerStorage.EC local gui = script.Parent.Parent.Parent.ThankYou script.Parent.MouseButton1Click:connect(function() tool:Clone().Parent = player.backpack script.Parent.Parent.Visible = false gui.Visible = true wait(3) gui.Visible = false end)
Since this is a local script, local scripts cannot access the ServerStorage. You should move EC to the ReplicatedStorage and change line 2 to:
local tool = game.ReplicatedStorage.EC
Local scripts cannot access the ServerStorage to make sure that exploiters cannot steal assets.
Services like ServerStorage
have their children hidden on localscripts. I suggest using remotes since regular scripts can see the children of ServerStorage
and you want to communicate across boundaries.
Samples:
Proof (assume you have an instance named "Potato" in serverstorage
):
LocalScript:
local ServerStorage = game:GetService("ServerStorage"); local Potato = ServerStorage:FindFirstChild('Potato'); print(Potato); --> nil;
Script:
local ServerStorage = game:GetService("ServerStorage"); local Potato = ServerStorage:FindFirstChild('Potato'); print(Potato); --> Potato;
Using remotes: Script:
local rep = game:GetService("ReplicatedStorage"); local RE = Instance.new("RemoteEvent"); RE.Parent = rep; RE.OnServerEvent:Connect(function(Player,Key) print(Player.Name,'pressed',Key);-- For me its "SoftlockedUnderZero pressed q" end);
LocalScript:
local players = game:GetService("Players"); local lp = players.LocalPlayer; local mouse = lp:GetMouse(); local rep = game:GetService("ReplicatedStorage"); local RE = rep:WaitForChild('RemoteEvent',math.huge); mouse.KeyDown:Connect(function(k) -- I pressed "q" RE:FireServer(k); end);