✓ Accepted answer
Alright, backtrack here.
Tools placed in StarterPack should replicate to the player's Backpack when they join the game and when their character spawns in. If you don't want a tool to be immediately equipped like this, you place it in a storage. Which storage? Preferrably ServerStorage, since ReplicatedStorage isn't a very secure place to keep tools.
Ok, now let's say you have a tool located in ServerStorage you want to give to the player. Adjust your PlayerAdded function so that it clones the tool out of ServerStorage and place it in the player. (Mind you, the script needs to be a normal script; local scripts can't access ServerStorage.) Should be a relatively simple fix.
In your case, you'd want the client to activate the signal to acquire the tool. For this, you'd utilize a RemoteEvent so the client sends the signal to the server, and the server is able to clone the tool into that player (RemoteEvent:FireServer() will feed the server the client that fired the event). Place the RemoteEvent in ReplicatedStorage so both the client and the server can access the event.
Example usage of a RemoteEvent, just to show you how to use one:
Client
local event = game:GetService("ReplicatedStorage"):WaitForChild("Event")
local msg = "Hello"
script.Parent.MouseButton1Click:Connect(function()
event:FireServer(msg)
end)
Server
local event = game:GetService("ReplicatedStorage"):WaitForChild("Event")
event.OnServerEvent:Connect(function(client, msg)
print(msg)
end)
1 comment
That code is nice!