This script detects when a part is touched and then gives the player how touched it speed boost. I have a lot of PowerUp parts all over workspace inside all different folders. Is there a way to make one script that can make all of them work by using one script.
local speedBoostPart = script.Parent
local speedBoostDuration = 2
local speedMultiplier = 2
local cooldownTime = 5
local canBoost = true
local function onTouched(hit)
local character = hit.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid and canBoost then
local originalSpeed = humanoid.WalkSpeed
humanoid.WalkSpeed = originalSpeed * speedMultiplier
-- Change the part's surface material to SmoothPlastic
speedBoostPart.Material = Enum.Material.SmoothPlastic
canBoost = false
wait(speedBoostDuration)
humanoid.WalkSpeed = originalSpeed
-- Reset the part's surface material
speedBoostPart.Material = Enum.Material.Smooth
wait(cooldownTime)
canBoost = true
end
end
speedBoostPart.Touched:Connect(onTouched)