Hello everybody! I am a new scripter who is trying to make a powerup that disapears and reappears after a set time. The powerup itself works, but for some reason whenever I try to change the properties of it, it affects the player. I have a script in the workspace that effects all parts named "PowerUp", and I am still learning so any help is highly appreciate.
Here is the code:
local WalkSpeedBoost = script.WalkSpeedBoostValue.Value
local JumpHeightBoost = script.JumpHeightBoostValue.Value
local Duration = script.DurationValue.Value
local CanTouch = true
local Transparency = 0
local function PowerUpFunction(PowerUpParts)
local Player = PowerUpParts.Parent:FindFirstChild("Humanoid")
if Player then
print("PowerUp Activated")
Player.WalkSpeed = Player.WalkSpeed + WalkSpeedBoost
Player.JumpHeight = Player.JumpHeight + JumpHeightBoost
PowerUpParts.CanTouch = false -- Effects player, not part
PowerUpParts.Transparency = 1 -- Effects player, not part
task.wait(Duration)
Player.WalkSpeed = Player.WalkSpeed - WalkSpeedBoost
Player.JumpHeight = Player.JumpHeight - JumpHeightBoost
task.wait(Duration)
PowerUpParts.CanTouch = true -- Effects player, not part
PowerUpParts.Transparency = 0 -- Effects player, not part
end
end
for PowerUpDetection, PowerUpParts in pairs(game.Workspace:GetChildren()) do
if PowerUpParts.Name == "PowerUp" then
print("PowerUpParts Found")
PowerUpParts.Touched:Connect(PowerUpFunction)
end
end
** You are now Level 1! **