I have asked a question on the roblox dev fourm and updated my code and removed the hidden stat (but i dont think its the error) and moved some code around but nothing is fixed and it almost feels like it got worse:
Speed Pad Code:
01 | local speedBoost = script.Parent |
02 | local mainSpeedValue = 35 -- how much the speed pad changes your speed to |
03 | local OriginalValue = 30 -- how much the normal player gets in the game |
04 | local function SteppedOn(part) |
05 | game:WaitForChild( "Players" ).PlayerAdded:Connect( function (plr) |
06 | local parent = part.Parent |
07 | local data = game.Players:GetPlayerFromCharacter(parent) |
08 | if game.Players:GetPlayerFromCharacter(parent) then |
09 | parent.Humanoid.WalkSpeed = mainSpeedValue |
10 | parent.Humanoid.WalkSpeed = parent.Humanoid.WalkSpeed + plr.leaderstats.extraspeed.Value |
11 |
12 | wait( 5 ) |
13 | parent.Humanoid.WalkSpeed = OriginalValue |
14 | parent.Humanoid.WalkSpeed = parent.Humanoid.WalkSpeed + plr.leaderstats.extraspeed.Value |
15 |
16 | end |
17 | end ) |
18 | end |
19 |
20 | speedBoost.Touched:connect(SteppedOn) |
Starting Speed Pad Code (you know the yellow bar at the start of those speed games):
01 | debounce = true |
02 | -- Debounce variable (so your function doesn't repeat itself) |
03 | function YourWalkspeedIsChanged(hit) -- Function, with "hit" being the argument (or the object that touches your part) |
04 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
05 | if hit.Parent:findFirstChild( "Humanoid" ) ~ = nil and debounce = = true then -- Seeing if there's humanoid |
06 | debounce = false -- "Locks" function, so it won't repeat |
07 | hit.Parent.Humanoid.WalkSpeed = 30 -- Changes the walkspeed |
08 | hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed + player.leaderstats.extraspeed.Value |
09 | debounce = true -- "Unlocks" function, so the function can run again |
10 | end |
11 | end |
12 |
13 | script.Parent.Touched:connect(YourWalkspeedIsChanged) -- Connection line, to run the function |
Coin Code:
01 | local db = true |
02 | script.Parent.Touched:connect( function (hit) |
03 | if hit.Parent:FindFirstChild( "Humanoid" ) ~ = nil then |
04 | if db = = true then |
05 | db = false |
06 | script.Parent.Transparency = 1 |
07 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
08 | local respawntime = script.Parent.RespawnTime.Value |
09 | player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 5 + player.leaderstats.extracoins.Value -- change 'Coins' to your currency name. |
10 | script.Sound:Play() |
11 | wait( 1 ) |
12 | script.Parent.Transparency = 1 |
13 | wait(respawntime) -- time before respawn |
14 | db = true |
15 | script.Parent.Transparency = 0 |
16 | end |
17 | end |
18 | end ) |
Updated Start Pad Speed Code (no errors in output, does not work)
I'd also prefer to be able to simply add a main speed value like it goes to 30 as the starting speed, then speed pads, charms, etc increase your speed, Bring in the ExSpeed leaderstat, as i dont wanna have to mess with making sure the ExSpeed is correct almost every second as that would cause lag.
01 | script.Parent.Touched:connect( function (P) -- Connects a function with the argument P which is the part that touched the part |
02 | local PL = game.Players:WaitForChild(P.Parent.Name) -- Gets the player |
03 | local H = PL.Character:WaitForChild( "Humanoid" ) |
04 |
05 | if PL then -- If player is found then |
06 | if H then -- If humanoid is found then |
07 |
08 | H.WalkSpeed = 30 -- Adds the extra speed to the original walk speed |
09 | H.WalkSpeed = H.WalkSpeed + PL.leaderstats.ExSpeed.Value |
10 | wait( 1 ) |
11 |
12 |
13 | end |
14 | end |
15 | end ) |
For the speed pad start use this:
01 | script.Parent.Touched:connect( function (P) -- Connects a function with the argument P which is the part that touched the part |
02 | local PL = game.Players:WaitForChild(P.Parent.Name) -- Gets the player |
03 | local H = PL.Character:WaitForChild( "Humanoid" ) |
04 |
05 | if PL then -- If player is found then |
06 | if H then -- If humanoid is found then |
07 | H.WalkSpeed = H.WalkSpeed + PL.leaderstats.extraspeed.Value -- Adds the extra speed to the original walk speed |
08 | end |
09 | end |
10 | end ) |
For the coin collection use this:
01 | script.Parent.Touched:connect( function (P) -- Connects a function with the argument P which is the part that touched the part |
02 | local player = game.Players:WaitForChild(P.Parent.Name) -- Gets the player |
03 |
04 | if player then -- If player is found then |
05 | local respawntime = script.Parent.RespawnTime.Value -- Gets the respawn time |
06 | player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 5 + player.leaderstats.extracoins.Value -- Adds the coins |
07 | script.Sound:Play() -- Plays the sound |
08 | repeat -- Repeats function |
09 | wait( 0.1 ) -- Waits 0.1 second |
10 | script.Parent.Transparency = script.Parent.Transparency + 0.1 -- Adds 0.1 transparency to the part's transparency |
11 | until script.Parent.Transparency = = 1 -- Repeats till the part is transparent |
12 | wait(respawntime) -- Waits the respawn time |
13 | repeat -- Repeats function |
14 | wait( 0.1 ) -- Waits 0.1 second |
15 | script.Parent.Transparency = script.Parent.Transparency - 0.1 -- Removes 0.1 transparency from the part's transparency |
16 | until script.Parent.Transparency = = 0 -- Repeats till the part is transparent |
17 | end |
18 | end ) |