Answered by
4 years ago Edited 4 years ago
You must use a RemoteEvent
as the client (LocalScript(s)) cannot access ServerStorage and the client cannot just give itself tools. To fix this, insert a RemoteEvent into ReplicatedStorage
and name it "GiveTool". Now change the LocalScript's code to this
1 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
3 | script.Parent.MouseButton 1 Click:Connect( function () |
4 | ReplicatedStorage.GiveTool:FireServer() |
This will fire the RemoteEvent when you click the button.
Now insert a ServerScript
(aka. Normal Script) into ServerScriptService
1 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
2 | local Tool = game:GetService( "ServerStorage" ).RPK |
4 | ReplicatedStorage.GiveTool.OnServerEvent:Connect( function (player) |
5 | Tool:Clone().Parent = player.Backpack |
Now the OnServerEvent
RBXScriptSignal will fire when the RemoteEvent is fired, in this case, when the button is clicked. Then the script will clone the tool and place it in the player's backpack. Hopefully, this helped you! For more information on RemoteEvents and RemoteFunctions, go here.