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

GUI tool giver not giving tool when player clicks TextButton?

Asked by
vocful 6
5 years ago

Goal: Player touches brick and opens a certain ScreenGUI. Then the user clicks on a TextButton to get a tool in their backpack.

Problem: The GUI (TextButton) is not giving the tool when clicked by a player.

Resources:

On Touch "Brick": on touch, gives the player a certain ScreenGUI "Giver": gives a gui whenever a players touches "Brick" "Gui": the ScreenGui that shows when a player touches "Brick" (activated by 'Giver' script)

Tool Giver "Gui": the ScreenGui that shows when a player touches "Brick" (activated by 'Giver script. this is located in "Brick" with the 'Giver' script "Gui" (ScreenGui) -> "Frame" -> "TextButton" -> "Tool Giver" (local script)

Brick shows GUI on Touch

01local sp = script.Parent
02local db = true
03local gui = script.Parent.Gui
04 
05sp.Touched:connect(function(hit)
06 if hit and hit.Parent:findFirstChild("Humanoid") and db then
07  db = false
08  local player = game.Players:GetPlayerFromCharacter(hit.Parent)
09  if not player.PlayerGui:findFirstChild("Pop up") then
10  local newqui = gui:Clone()
11  newqui.Parent = player.PlayerGui
12  end
13 
14  db = true
15 end
16end)

GUI Tool Giver (Local script)

1local button = script.Parent
2local tool = game.ServerStorage.ExampleTool
3local plr = game.Players.LocalPlayer
4 
5button.MouseButton1Click:Connect(function()
6    tool:Clone().Parent = plr.Backpack
7end)

Output: Script 'Players.ReasonxbIe.PlayerGui.Gui.Frame.TextButton.LocalScript', Line 2 -> local tool = game.ServerStorage.ExampleTool

Final Request: May anybody help me? I would like it so when a player touches a certain part, a ScreenGui will appear for ONLY that player. Then, the player can choose a tool by clicking the TextButton. When they click the button, they will be given the tool and the ScreenGui will close. They should be able to touch the part again and get another tool.

0
A local script can not access ServerStorage. DBoi941 57 — 5y
0
Where should I move the ExampleTool to then? vocful 6 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

LocalScript's cannot access ServerStorage as they run on the client, not the server. It's called "ServerStorage" for a reason. Instead, put ExampleTool in ReplicatedStorage. Try this once you've done it:

1local button = script.Parent
2local tool = game.ReplicatedStorage:WaitForChild("ExampleTool")
3local plr = game.Players.LocalPlayer
4 
5button.MouseButton1Click:Connect(function()
6    tool:Clone().Parent = plr.Backpack
7end)
0
Thank you so much! vocful 6 — 5y
0
No problem. youtubemasterWOW 2741 — 5y
Ad
Log in to vote
1
Answered by
DesertusX 435 Moderation Voter
5 years ago

LocalScripts can't access ServerStorage, so move the tool to ReplicatedStorage.

Answer this question