Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

stat will not add onto a player's speed along with another number and my coin wont collect properly?

Asked by 5 years ago
Edited 5 years ago

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:

01local speedBoost = script.Parent
02local mainSpeedValue = 35 -- how much the speed pad changes your speed to
03local OriginalValue = 30 -- how much the normal player gets in the game
04local 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)
18end
19 
20speedBoost.Touched:connect(SteppedOn)

Starting Speed Pad Code (you know the yellow bar at the start of those speed games):

01debounce = true
02-- Debounce variable (so your function doesn't repeat itself)
03function 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
11end
12 
13script.Parent.Touched:connect(YourWalkspeedIsChanged)   -- Connection line, to run the function

Coin Code:

01local db = true
02script.Parent.Touched:connect(function(hit)
03if 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
17end
18end)

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.

01script.Parent.Touched:connect(function(P) -- Connects a function with the argument P which is the part that touched the part
02local PL = game.Players:WaitForChild(P.Parent.Name) -- Gets the player
03local H = PL.Character:WaitForChild("Humanoid")
04 
05if 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
14end
15end)
0
Why do you have a player.leaderstats.extraspeed? firestarroblox123 440 — 5y
0
You could just say humanoid.WalkSpeed = Whatever You Want The WalkSpeed To Be firestarroblox123 440 — 5y
0
but i want the players to be able to upgrade their extra speed but they also get a normal value at the start too plus their extra speed RobloxGameingStudios 145 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

For the speed pad start use this:

01script.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:

01script.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
18end)
0
Does not work even though I made extraspeed a diff value to test... Also can i add a main speed value then add the extra speed onto it?? No errors in output. This is so werid. RobloxGameingStudios 145 — 5y
0
ill put my updated script in the bottom of my question RobloxGameingStudios 145 — 5y
Ad

Answer this question