Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Tool giver gui doesnt give tool on clicked?

Asked by 5 years ago

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

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. Bylli_Oruze 38 — 5y

2 answers

Log in to vote
0
Answered by
sayer80 457 Moderation Voter
5 years ago
-- 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)
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" sayer80 457 — 5y
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 Bylli_Oruze 38 — 5y
0
I could hug both of you rn Bylli_Oruze 38 — 5y
0
Thank you sayer80 457 — 5y
Ad
Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

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.

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) Bylli_Oruze 38 — 5y
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. chomboghai 2044 — 5y
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. Bylli_Oruze 38 — 5y
0
i could send you a link to the game to see how its all set out? Bylli_Oruze 38 — 5y

Answer this question