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

Where's the problem in this point-giving script? Everything works except the part with giving points

Asked by 5 years ago
Edited 5 years ago

I don't know where is the problem in this script, points aren't awarded. - No errors are shown in the Output (edited script, but still not working)

sp=script.Parent

fatalthreshhold=400

safethreshhold=65

lastvelocity=0

while true do
    wait()
    local t=sp:FindFirstChild("UpperTorso")
    if t~=nil then
        local currentvelocity=(t.Velocity).magnitude
        local cost=currentvelocity-safethreshhold
        if cost>0 then
            local Reward = cost/(fatalthreshhold-safethreshhold)*100
            local h=sp:FindFirstChild("Humanoid")
            local thisplr = game.Players:findFirstChild(h.Parent.Name)
            if (thisplr~=nil) then
            local stats = thisplr:findFirstChild("leaderstats")
            if (stats~=nil) then
            if h then
                function rewarding(plr)
                plr.stats.points.Value = plr.stats.points.Value + Reward
            end 
        end
        lastvelocity=currentvelocity
    end
end
end
end
end

1 answer

Log in to vote
0
Answered by 5 years ago

You attempted a PlayerAdded event, but you made it incorrectly. Also, PlayerAdded fires when a new player joins the game, so if your if statement is true, the game needs to wait for another player to join to give that player the leaderstats. Put this as a script in ServerScriptService.

game:GetService("Players").PlayerAdded:Connect(function(plr)
    local stats = Instance.new("Folder") -- parent argument is deprecated, assign parent as last property in another line
    stats.Name = "leaderstats"
    stats.Parent = plr

    local points = Instance.new("IntValue")
    points.Name = "Points"
    points.Value = 0
end)

You'll want to get the player from another script to reward them their points.

On a side note, the parent argument to Instance.new is deprecated and is known to slow down performance. :connect() is also deprecated and has a newer alternative, :Connect(), which should be used instead. i

0
I've tried my best but point-giving script still does not work, I've used your script and edited it to work but still I have no idea what am I doing wrong with the point giving script (I've edited script in question) Pikol53 0 — 5y
0
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + AMOUNT HERE User#19524 175 — 5y
0
thanks, worked Pikol53 0 — 5y
Ad

Answer this question