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

GUI that gives gears, gears don't work when given?

Asked by 4 years ago

So I'm currently trying to make a GUI that gives the player the gear they so choose. I thought I found something that worked (script I found in another GUI), but when the player got the tool, it was unusable. I also found out that only the play could see that weapon, not others.

So this is what I found and used:

local p = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local tool = script.Parent.BlackironKatana:Clone()
    tool.Parent = p.Backpack
end.

Any help on this would be greatly appreciated, once this is out the way, it's off to the fun of making the world :)

1 answer

Log in to vote
0
Answered by
zomspi 541 Moderation Voter
4 years ago
Edited 4 years ago

I had this same problem, the issue is you are using a local script to try and give them, you need to use a remote event and a server script. Put a remote event in replicated storage called "fire". Put a server script in server script service.

Local script:

script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.fire:FireServer()

end)

Server script:

game.ReplicatedStorage.fire.OnServerEvent:Connect(function(player)
local tool = script.Parent.BlackironKatana:Clone() -- Modify this to be the directory of the gear, e.g game.ReplicatedStorage.BlackironKatana:Clone()
    tool.Parent = player.Backpack
end)

A Remote Event is used to send a message from the client to the server or the other way round. In your case, you need to give a message to the server. That message is the fact that the player clicked the button, and now should receive the gear.

If I helped please accept this, if you need any more information on how to use remote event please ask

0
Alright, I've got the remote event "fire" in replicated storage, and I've got the script in Server Script Service, so how do I have the Gui send the message to the server? Currently it's using that local script. And thank you for the help, I was in need a pointer in the right direction :) mullenman 4 — 4y
0
So in the local script in the GUI, paste the local script above into it, change the first line to suite you, basically, when the button is clicked, it gets the remote event in replicated storage and fires the server, that is the command, FireServer() zomspi 541 — 4y
0
It worked wonders! Now the gear can be used. Now I've got a working Gui :) mullenman 4 — 4y
0
Thanks for the help zomspi, learned a bit today! I can safely call this solved. mullenman 4 — 4y
0
Glad I helped, thanks! zomspi 541 — 4y
Ad

Answer this question