Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't the GUI give me the tool to my backpack?

But I want the card to work on doors, which is not working.

local p = game.Players.LocalPlayer 
local button = script.Parent
local backpack = p.Backpack
local tool = game.ReplicatedStorage:WaitForChild("Room 101") 

button.MouseButton1Click:connect(function()
        local nTool = tool:Clone()
        nTool.Parent = backpack
    end)

This is code is in a local script inside a button.

1 answer

Your issue is related to Filtering Enabled. Because you're adding the tool to the client's Backpack via a local script, the change will not be replicated to the server. To fix this, you simply need to utilize a Remote Event to tell the server to make the action once the MouseButton1Click event is fired.

--Server Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = Instance.new("RemoteEvent")
local Remote.Parent = ReplicatedStorage --create remote

Remote.OnServerEvent:Connect(function(player,tool)
   local NewTool = tool:Clone()
   NewTool.Parent = player.Backpack
end)

--Local Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage:WaitForChild("RemoteEvent")
local button = script.Parent
local tool = ReplicatedStorage:WaitForChild("Room 101")

button.MouseButton1Click:Connect(function()
   Remote:FireServer(tool) --tell the server to clone the tool
end)

If you have any questions regarding this code, feel free to leave them in the comments. I'm happy to answer!

##Resources:

Remote Events

##Accept and upvote if this helps!

1 comment

0

Sorry it late but some reason its not working.

This discussion is preserved as it was. New answers, comments, and votes are closed.