Hello, so i got a script in which you can search a trash can and get random tools, the trashcan has a proximity prompt inside of it, and here’s the local script that’s inside the proximity prompt:
local event = game:GetService("ReplicatedStorage").TrashCan
script.Parent.Triggered:Connect(function()
event:FireServer()
end)
and here’s the serverscript:
local player = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
game.Players.PlayerAdded:Connect(function(PLAYERS)
local function GivePlayerRandomTools()
local Guns = game:GetService("ReplicatedStorage").TheTools:GetChildren()
local randomGun = Guns[math.random(1, #Guns)]:Clone()
randomGun.Parent = player.Backpack -- It gets sent to the player's backpack
end
rs.TrashCan.OnServerEvent:Connect(GivePlayerRandomTools)
end)
local function GivePlayerRandomTools(player)
local Guns = game:GetService("ReplicatedStorage").TheTools:GetChildren()
local randomGun = Guns[math.random(1, #Guns)]:Clone()
randomGun.Parent = player.Backpack -- It gets sent to the player's backpack
end
script.Parent.Triggered:Connect(function(player)
GivePlayerRandomTools(player)
end)