Help making tool giver gui

I was scripting tool giver gui but its working but other players cant see the tool when equiped. I have alredy gui but i think issue is its in local script that gives tool when gui is clicked. So i tried change local script to script and still not working. So the tool giver is not working.
So i dont know how to make it the tool visible for all players when equipped so please help because i have no idea how to solve this issue.

Script what i used:

local tool = game.ReplicatedStorage.Food.Salad 
local button = script.parent
local plr = game.Players.LocalPlayer
button.MouseButton1Click:Connect(function()
	tool:Clone().Parent = plr.Backpack
end)
3 Likes

Hiya! Hope you find this code useful.

local Button = script.Parent
local Salad= game.ReplicatedStorage.Food.Salad
local Player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
    local SaladClone = Salad:Clone()
    SaladClone.Parent = Player.Backpack
end)

@Ligij

4 Likes

Code is working but still when i am in team test i can see i have tool equipped but my friend only see im holding nothing

You shouldnt do this on the client, use remote events. For example, if a player clicks the button, it will fire a server event and then a server script listening to that event would give the player his tool.

1 Like

Ahh, I see. I get what you mean now.

1 Like

Im kinda new to scripting so i dont know what you mean remote events and firing them

local button = script.Parent
local salad = game.ReplicatedStorage.Food.Salad
local plr = game.Players.LocalPlayer

local saladEvent = -- Your event path here

button.MouseButton1Click:Connect(function()
	saladEvent:FireServer()
end)
1 Like

Should i make remote events on every single giver script? because i dont have only one give i have like 10 gui clickers

Local script

local button = script.Parent
local salad = game.ReplicatedStorage.Food.Salad
local plr = game.Players.LocalPlayer

local saladEvent = -- Your event path here

button.MouseButton1Click:Connect(function()
	saladEvent:FireServer(salad)
end)

Server Script

local saladEvent = -- Your event path here
	
saladEvent.OnServerEvent:Connect(function(plr, tool)
	local toolClone = tool:Clone()
	toolClone.Parent = plr.Backpack
end)
10 Likes

This should give you some knowledge on server side and client side:

LocalScripts will run on a player’s computer. So, when you see a game with a GUI, opening that GUI is done by a LocalScript, since it only opens for that player.
Server scripts are scripts that run on the server, meaning it effects everyone and everything on the server. This means, to give a player a tool that’s visible to the rest of the server, you need to use a RemoveEvent.

RemoveEvents let you send data from the client (when the player clicks the button) to the server (to give the tool).
If you do not understand how to use RemoveEvents, this video from TheDevKing should help you: Advanced Roblox Scripting Tutorial #8 - Remote Events & Remote Functions (Beginner to Pro 2019) - YouTube

1 Like

You only need to use one event for this, but you will need to pass different arguments for example, event:FireServer(salad) → event:FireServer(burger)

1 Like

Where do i have to put server script? Do i have put remote event in replicated storage?

Yes, put the remote event there, and put script under ServerScriptService

1 Like

Just remember it’s better to understand the code than to copy it. Try to play around with the script rather than just pasting it and admiring what it does.

On the devforum we’re not normally allowed to give you code, but since people already have you may as well learn off of it.

1 Like

Uhhh its making me error Serverscriptstorage.Script apptempt to index with Clone

Can you send screenshots please?

1 Like

You arent passing the salad as an argument in the local script.

1 Like

You’re references 2 completely different events.

1 Like

Did you watch the video I sent you earlier? It should clear up your confusion about remote events

1 Like