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

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

Asked by 5 years ago

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

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

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!

0
Sorry it late but some reason its not working. Luke2323244 17 — 5y
Ad

Answer this question