hello, I’m trying to make a powerup script where an item spawns on a timer, but wont spawn if no one has picked up the item. The problem is that the Touched event to pick up the item isnt firing correctly. here is the code: (powerup is a tool)
local powerup = game.ServerStorage.powerup
local debounce = false
while true do
print("SPEEDBOOST SPAWNED!")
power = powerup:Clone()
power.Parent = game.Workspace
power.powerup.Position = Vector3.new(-59, 27.76, 21.5)
wait(15)
while power.Parent == game.Workspace do
wait(10)
end
end
power.powerup.Touched:Connect(function(hit)
if debounce == false then
debounce = true
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
power.Parent = Player:WaitForChild("Backpack")
elseif hit.Parent.Parent:FindFirstChild("Humanoid") then
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent.Parent)
power.Parent = Player:WaitForChild("Backpack")
end
end
wait(1)
debounce = false
end)
The script is in ServerScriptService. Thanks in advance!