#Beginner Help

1 messages · Page 1 of 1 (latest)

ashen trail
#

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

#

I've been trying differnet things for about 30 minutes now.

#

Heres a picture of the workspace too (the only thing in the powerups are highlights)

primal stag
#

please use this for your code

vagrant salmonBOT
#

studio** You are now Level 1! **studio

ashen trail
#

Ohh I know what you mean, I'll do that tomorrow

#

When im on

round mesa
#

you set the variables at the beginning to the values of the valuebase instances WalkSpeedBoostValue etc. etc. at that point in time instead of to the instances directly and then using the instance.Value later on

also, workspace:GetChildren is potentially a massive shitload of instances of which you may want to pool together inside a folder instead. moreover, consider putting a touched event on the player's rig instead of every "power up part" so that you do not have to have potentially significantly more connections open simultaneously.