✓ Accepted answer
You can have a remote event that gives a player the tool:
Create a RemoteEvent in your ReplicatedStorage and name it GiveItem
In a local script, fire that remote event with the name of the tool you want to give the player
giveItem = game.ReplicatedStorage.GiveItem
giveItem:FireServer("TG45")
We can catch that remote event on the server. The following code below runs giveItem.OnServerEvent:Connect(function(player, itemBeingGiven) when the player fires the remote event from a localscript using the code I posted above.
We check if the item that the player is trying to get exists and if the player is allowed to have that tool using the playerCanHaveTool function.
playerCanHaveTool can check for anything.
A player can fire the remote event and give themselves any tool we want, but this function stops them from actually receiving the tool if they're not allowed. An example of this is if the player tries to buy a tool and they don't have enough money, this function will stop them from getting that item. Let me know if you have any questions.
giveItem = game.ReplicatedStorage.GiveItem
rs = game:GetService("ReplicatedStorage")
function playerCanHaveTool()
if (they can have the tool)then
return true
else
return false
end
end
giveItem.OnServerEvent:Connect(function(player, itemBeingGiven)
local tool = rs:FindFirstChild(itemBeingGiven)
if(tool and playerCanHaveTool())then
local clone = tool:Clone()
clone.Parent = player.Backpack
end
end)
1 comment
you will have to use remotes if your game is FE