Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Tool giver gui doesnt give tool on clicked?

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

1 comment

0

I also get the problem that if i did get the weapon, it would only be on my side, so i could go kill someone, but they would only die for me.

2 answers

✓ Accepted answer
-- 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)

4 comments

0

Put this into command input if you dont know how to create a remotevent: local remote = Instance.new("RemoteEvent") remote.Parent = game.ReplicatedStorage remote.Name = "ToolGiver"

0

Bro thank you so much, ive sat and tried over and over to get something like this to work for over a year now, thankyou

0

I could hug both of you rn

0

Thank you

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.

4 comments

0

Im sorry i dont understand, do i use a normal script, and if i do where do i put it? (Im not good with the whole client side / server side stuff)

0

Yes, a normal script. Where you put it depends on the structure of your game but it would most likely be ServerScriptService. You would need to add events that the client fires when they click the button and listen to those events from the server.

0

again i dont understand events and stuff, id read over wiki pages and the way roblox words it/ explains it is very confusing to me.

0

i could send you a link to the game to see how its all set out?

This discussion is preserved as it was. New answers, comments, and votes are closed.