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
4 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

local sp = script.Parent
local db = true
local gui = script.Parent.Gui

sp.Touched:connect(function(hit)
 if hit and hit.Parent:findFirstChild("Humanoid") and db then 
  db = false
  local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  if not player.PlayerGui:findFirstChild("Pop up") then 
  local newqui = gui:Clone()
  newqui.Parent = player.PlayerGui
  end

  db = true
 end
end)

GUI Tool Giver (Local script)

local button = script.Parent
local tool = game.ServerStorage.ExampleTool
local plr = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
    tool:Clone().Parent = plr.Backpack
end)

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 — 4y
0
Where should I move the ExampleTool to then? vocful 6 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 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:

local button = script.Parent
local tool = game.ReplicatedStorage:WaitForChild("ExampleTool")
local plr = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
    tool:Clone().Parent = plr.Backpack
end)
0
Thank you so much! vocful 6 — 4y
0
No problem. youtubemasterWOW 2741 — 4y
Ad
Log in to vote
1
Answered by
DesertusX 435 Moderation Voter
4 years ago

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

Answer this question