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

Why won't this script give a tool to whoever pushes the button?

Asked by
Hypoxla 125
4 years ago

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)

2 answers

Log in to vote
0
Answered by
Misqueso 145
4 years ago

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.

0
What does the welding script do? User#34929 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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);

Answer this question