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.
Ahh, I see. I get what you mean now.
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)
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)
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
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)
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
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.
Uhhh its making me error Serverscriptstorage.Script apptempt to index with Clone
Can you send screenshots please?
You arent passing the salad as an argument in the local script.
You’re references 2 completely different events.
Did you watch the video I sent you earlier? It should clear up your confusion about remote events
Try replacing saladEvent:FireServer() with saladEvent:FireServer(salad)
yes im going to watch it now i was just trying to solve it so im going to watch it
Do what tiger said, put salad inside the brackets in our local script and it will work.