I’m trying to create a powerup that increases speed. Here’s the script that handles picking up the powerup and respawning it:
local powerup = script.Parent
local db = powerup.db
local plrsService = game:GetService("Players")
for i, v in pairs(powerup:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if db.Value == false then
db.Value = true
local plr = plrsService:GetPlayerFromCharacter(hit.Parent)
plr.powerupEffects.speedSodaTime.Value = 7
print(plr.Parent)
wait(3)
db.Value = false
end
end)
end
end
And here’s the script for counting the time left on the powerup(it’s a LocalScript):
local plr = game.Players.LocalPlayer
local speedSodaTime = plr.powerupEffects.speedSodaTime
local speedSodaStatus = plr.powerupEffects.speedSodaStatus
speedSodaTime.Changed:Connect(function()
if speedSodaStatus.Value == false then
speedSodaStatus.Value = true
repeat
wait(1)
speedSodaTime.Value = speedSodaTime.Value - 1
until speedSodaTime.Value <= 0
speedSodaStatus.Value = false
end
end)
These scripts work perfectly when I pick up the powerup for the first time, but for some strange reason the GetPlayerFromCharacter part of the first script never executes after the first time.
Everything else still works after the first time. I’ve tried checking that the character model of the player isn’t counted as part of the powerup and simplifying the debounce for the powerup spawning, but I’m still stuck. Can anyone help me? I do need to have a IntValue or NumberValue representing the time left on the powerup, because they’re going to work like the powerups from Adventure Forward 2.
Also, does anyone have any optimizations for these scripts?