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:

local speedBoost = script.Parent
local mainSpeedValue = 35 -- how much the speed pad changes your speed to
local OriginalValue = 30 -- how much the normal player gets in the game
local function SteppedOn(part)
  game:WaitForChild("Players").PlayerAdded:Connect(function(plr)
  local parent = part.Parent
  local data = game.Players:GetPlayerFromCharacter(parent)
  if game.Players:GetPlayerFromCharacter(parent) then
    parent.Humanoid.WalkSpeed = mainSpeedValue
    parent.Humanoid.WalkSpeed = parent.Humanoid.WalkSpeed + plr.leaderstats.extraspeed.Value

    wait(5)
    parent.Humanoid.WalkSpeed = OriginalValue
    parent.Humanoid.WalkSpeed = parent.Humanoid.WalkSpeed + plr.leaderstats.extraspeed.Value

  end
  end)
end

speedBoost.Touched:connect(SteppedOn)

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

debounce = true
-- Debounce variable (so your function doesn't repeat itself)
function YourWalkspeedIsChanged(hit)    -- Function, with "hit" being the argument (or the object that touches your part)
  local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  if hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == true then -- Seeing if there's humanoid
    debounce = false                    -- "Locks" function, so it won't repeat
    hit.Parent.Humanoid.WalkSpeed = 30 -- Changes the walkspeed
    hit.Parent.Humanoid.WalkSpeed = hit.Parent.Humanoid.WalkSpeed + player.leaderstats.extraspeed.Value
    debounce = true                 -- "Unlocks" function, so the function can run again
  end
end

script.Parent.Touched:connect(YourWalkspeedIsChanged)   -- Connection line, to run the function

Coin Code:

local db = true
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
  if db == true then
    db = false
    script.Parent.Transparency = 1
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local respawntime = script.Parent.RespawnTime.Value
    player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 5 + player.leaderstats.extracoins.Value -- change 'Coins' to your currency name.
    script.Sound:Play()
    wait(1)
    script.Parent.Transparency = 1
    wait(respawntime) -- time before respawn
    db = true
    script.Parent.Transparency = 0
  end
end
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.

script.Parent.Touched:connect(function(P) -- Connects a function with the argument P which is the part that touched the part
local PL = game.Players:WaitForChild(P.Parent.Name) -- Gets the player
local H = PL.Character:WaitForChild("Humanoid")

if PL then -- If player is found then
  if H then -- If humanoid is found then

    H.WalkSpeed = 30 -- Adds the extra speed to the original walk speed
    H.WalkSpeed = H.WalkSpeed + PL.leaderstats.ExSpeed.Value
    wait(1)


  end
end
end)
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:

script.Parent.Touched:connect(function(P) -- Connects a function with the argument P which is the part that touched the part
        local PL = game.Players:WaitForChild(P.Parent.Name) -- Gets the player
        local H = PL.Character:WaitForChild("Humanoid")

        if PL then -- If player is found then
            if H then -- If humanoid is found then
                H.WalkSpeed = H.WalkSpeed + PL.leaderstats.extraspeed.Value -- Adds the extra speed to the original walk speed
            end
        end
        end)

For the coin collection use this:

script.Parent.Touched:connect(function(P) -- Connects a function with the argument P which is the part that touched the part
        local player = game.Players:WaitForChild(P.Parent.Name) -- Gets the player

        if player then -- If player is found then
        local respawntime = script.Parent.RespawnTime.Value -- Gets the respawn time
        player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 5 + player.leaderstats.extracoins.Value -- Adds the coins
        script.Sound:Play() -- Plays the sound
        repeat -- Repeats function
        wait(0.1) -- Waits 0.1 second
        script.Parent.Transparency = script.Parent.Transparency + 0.1 -- Adds 0.1 transparency to the part's transparency
        until script.Parent.Transparency == 1 -- Repeats till the part is transparent
        wait(respawntime) -- Waits the respawn time
        repeat -- Repeats function
        wait(0.1) -- Waits 0.1 second
        script.Parent.Transparency = script.Parent.Transparency - 0.1 -- Removes 0.1 transparency from the part's transparency
        until script.Parent.Transparency == 0 -- Repeats till the part is transparent
        end
end)
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