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

I want a gui button to give me a weapon?

Asked by 3 years ago
Edited by Leamir 3 years ago

so i tried this code to give me a weapon on press of the button and it didnt work

local player = game.Players.LocalPlayer -- Refer to the Player
local tool = game.ReplicatedStorage.Sword -- Refer to the Tool

script.Parent.MouseButton1Down:connect(function() -- When it's clicked
    if player:FindFirstChild("Backpack") then -- Not sure why I added this
        tool:Clone().Parent = player.Backpack -- Clone the tool to their inventory
    end -- End the if function
end) -- End the MouseButton1Down function 
0
code block raid6n 2196 — 3y
0
alright, i showed an example raid6n 2196 — 3y

1 answer

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

You are cloning the tool with a LocalScript, but you can only clone with a server script, I believe. You'll have to use a RemoteEvent instead.

https://developer.roblox.com/en-us/api-reference/class/RemoteEvent

Example: (make sure you have a remoteevent inside of replicatedstorage)

button script:

local player = game.Players.LocalPlayer 

script.Parent.MouseButton1Down:connect(
    function()
        game.ReplicatedStorage.RemoteEvent:FireServer(player)
    end
)

backpack script inside of serverscriptservice:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(
    function(player)
        local tool = game.ReplicatedStorage.Sword
        tool:Clone().Parent = player.Backpack
    end
)

0
damn my grammar raid6n 2196 — 3y
0
i've just read this and i have no idea what any of this means ScottRulesAtAnything -1 — 3y
0
yh lemme edit raid6n 2196 — 3y
0
not that the website ScottRulesAtAnything -1 — 3y
View all comments (17 more)
0
i could show an example code raid6n 2196 — 3y
0
can you? im not very good with code lol ScottRulesAtAnything -1 — 3y
0
sure raid6n 2196 — 3y
0
thanks ScottRulesAtAnything -1 — 3y
0
do i use a script or a local script for the server bit? ScottRulesAtAnything -1 — 3y
0
script raid6n 2196 — 3y
0
thx ScottRulesAtAnything -1 — 3y
0
how do i do it with a weapon name 'trenchgun' ScottRulesAtAnything -1 — 3y
0
just change local tool = game.ReplicatedStorage.Sword raid6n 2196 — 3y
0
also it didnt work ScottRulesAtAnything -1 — 3y
0
wait im so confused are my weapons supposed to be in replicatesstorage? ScottRulesAtAnything -1 — 3y
0
yes raid6n 2196 — 3y
0
... ScottRulesAtAnything -1 — 3y
0
im trying it now... im testing it ScottRulesAtAnything -1 — 3y
0
didnt work, ScottRulesAtAnything -1 — 3y
0
I FIXED IT BUT IT GIVES ME BOTH WEAPONS AT THE SAME TIME 0_0 ScottRulesAtAnything -1 — 3y
0
and continues to give me them when i press repetitively ScottRulesAtAnything -1 — 3y
Ad

Answer this question