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.
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)
LocalScripts can't access ServerStorage, so move the tool to ReplicatedStorage.