In my game ive got a separate part of the map where players teleport and fight each other with weapons they choose from a gui that becomes visible when they teleport. the only problem is that when it comes to pressing the TextButton to give the weapon, it either gives me a broken tool or nothing at all.
local frame = script.Parent.Parent.Parent local tool = ("Hammer") local player = game.Players.LocalPlayer repeat wait(0.1) until player.Backpack script.Parent.MouseButton1Down:connect(function() game.Lighting:FindFirstChild(tool):Clone().Parent = player.Backpack frame:remove() end)
This is a local script inside of a textbutton
-- this comes into the localscript inside the button local frame = script.Parent.Parent.Parent local tool = ("Hammer") script.Parent.MouseButton1Down:Connect(function(ts) game.ReplicatedStorage.ToolGiver:FireServer(tool) end)
Rightclick on ReplicatedStorage insert object remoteevent then name it ToolGiver
now add a script inside serverscriptservice and put this in it :
-- put into serverscriptservice game.ReplicatedStorage.ToolGiver.OnServerEvent:Connect(function(plr,tool) game.Lighting:FindFirstChild(tool):Clone().Parent = plr.Backpack end)
The issue is primarily from the fact that this script is placed inside of a LocalScript
. Any changes made to the game from a LocalScript
can only be seen by the client that the script ran on. Therefore, if you try to give a sword to the player using that script, it will only give it to him on their client and nobody else (not even the server) would acknowledge that this person has a sword.
To fix this, simply handle the giving of the weapon through a Script
on the server side instead.