Random tool giver doesn't work (proximity prompt)

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)

Make sure its a serverscript inside the proximity prompt. No need for an event, you can just do it all in the server script.

the problem is that it worked before when it was a serverscript, but then the tools went to everyone not the certain player.

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)

alright so it gives me tools, but i still gotta try it in the local server thingy, brb.

it actually worked, idk what mistakes i did but thats not important.

Without seeing your before serverscript I couldn’t say but remember that local scripts don’t work anywhere in the workspace.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.