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

Adding to Leaderstats On touch?

Asked by 6 years ago

Most of the code works

debounce = true
if debounce then
    script.Parent.Transparency = 0
elseif not debounce then
    script.Parent.Transparency = .7
end

function OnHit(hit)
    if debounce == true then
        debounce = false -- prevents script to run event again.
print("All Good")
    local human = hit.Parent
    if human then
        local player = game.Players:GetPlayerFromCharacter(human)
        player.leaderstats.Speed.Value = player.leaderstat.Speed.Value+10 
        wait(5)
         debounce = true -- allows script to run event again
        end
    end
    end

    script.Parent.Touched:Connect(OnHit)

Thats all the code. But this part

local human = hit.Parent
    if human then
        local player = game.Players:GetPlayerFromCharacter(human)
        player.leaderstats.Speed.Value = player.leaderstat.Speed.Value+10 

GetPlayerFromCharacter to Change Speed

1 answer

Log in to vote
0
Answered by 6 years ago

Oh I fixed it

debounce = true
if debounce then
    script.Parent.Transparency = 0
elseif not debounce then
    script.Parent.Transparency = 1
end

function OnHit(hit)
    if hit.ClassName == "Part" then
    if debounce == true then
        debounce = false -- prevents script to run event again.
            print("All Good")
         if hit.Parent then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent);
            print("Me too")
            if player then
                player.leaderstats.Speed.Value = player.leaderstats.Speed.Value+10
                print("Yes")
                print(player.leaderstats.Speed.Value)
                wait(5)
                debounce = true -- allows script to run event again
        else
            print ("No")
            local a = hit.Parent.Parent
            local player2 = game.Players:GetPlayerFromCharacter(a)
            player2.leaderstats.Speed.Value = player2.leaderstats.Speed.Value+10
            print(player2.leaderstats.Speed.Value)
            wait(5)
            debounce = true
                end 
            end
        end
    end
end

    script.Parent.Touched:Connect(OnHit)

Even if it returns No then it will still work

Ad

Answer this question