local players = game:GetService('Players')
local player = players.LocalPlayer
yes.MouseButton1Click:Connect(function(player)
local food = game.ReplicatedStorage.Sugar:Clone()
food.Parent = player.Backpack
end)
It works on other things just not GUIs, the player parameter is to work with the script that you see but apparently for adding it to GUI buttons it doesnt work
local remote = game.ReplicatedStorage:WaitForChild("RemoteEvent") -- You have to create remote event
local food = game.ReplicatedStorage:WaitForChild("Sugar")
local yes = script.Parent
yes.Activated:Connect(function()
remote:FireServer(food)
end)
And… this is server script.
local remote = game.ReplicatedStorage:WaitForChild("RemoteEvent") -- You have to create remote event
remote.OnServerEvent:Connect(function(Plr, food)
local clone = food:Clone()
clone.Parent = Plr.Backpack
Didn’t work, maybe an idea on where I should place the local script/regular script with the remote event? Nothing is coming out in the output either which is confusing
So, youre supposed to place the local script inside the button, and if its on startergui, its gonna always be on the player(ignore this if you manually summon the gui),once the player click on it, you will use the remotevent to the server to give the player the tool
Now, to use the mouse1click event, you can put the script inside the button, and do
local button = script.parent
button.MouseButton1Click:Connect(function()
--code here (use remoteevent like remotevent:fireserver or smth im on phone)
end)
Forgot to tell you that, remotevent always send the player data if its local so you dont need any parameters for the player, only the food(sorry i was on phone and on school at that time)