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

How to make it work?

Asked by 8 years ago

Hello, I have a large problem to fix. I want to add to my place Points Leaderboard GUI and when you hit part which give you points it should show how many points i have in GUI. Here is some scripts: Leaderboard GUI:

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model",player)
    leaderstats.Name = "leaderstats"

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

    local P = game.StarterGui.Points.Frame.Point
end)

wait(0)
P.Text = "Points: "..points.Value

Maybe i added it to wrong place. Script is in StarterGUI>Points

Here is script from Point part which after hit should give me 1 point.

waittime = 5 -- Time Between each hit
amnt = 4 --how much you get for it
function onTouched(part)
    local h = part.Parent:findFirstChild("Humanoid")
    if (h~=nil) then
        local thisplr = game.Players:findFirstChild(h.Parent.Name)
        if (thisplr~=nil) then
            local stats = thisplr:findFirstChild("leaderstats")
            if (stats~=nil) then
                local score = stats:findFirstChild("Points")
                if (score~=nil) then
                    score.Value = score.Value + amnt
                end
            end
        end

        script.Parent.Transparency = 1
        script.Disabled = true
        wait(waittime)
        script.Parent.Transparency = 0
        script.Disabled = false     


    end
end

script.Parent.Touched:connect(onTouched)

So i don't know how to make them work together.

0
Oh, sorry about never responding. I was offline all of yesterday. I had things going on. dyler3 1510 — 8y

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
8 years ago

Wut Be Da Problem?

For the most part you have it correct, but you need to fix a couple things. First, you tried to set "leaderstats" as a model. "leaderstats" needs to be an IntValue, and your "points" should be a NumberValue. The only other thing in your first script is that you only update the value once. You need it to stay updated in order for the player to constantly be able to see there amount of points.

In your second script, pretty much everything is correct except the way you Debounced. To properly debounce, you need to set up and if statement with a variable that turns on/off.


Boi, Let's Fix Dis

Now, here's the first script:

To fix this, put the script in the Workspace, and change it to this:

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("IntValue",player)
    leaderstats.Name = "leaderstats"

    local points = Instance.new("NumberValue",leaderstats) --Changed to NumberValue
    points.Name = "Points"
    points.Value = 0

    local P = game.StarterGui.Points.Frame.Point
    P.Text = "Points: "..points.Value
end)

And da second one:

To fix this script, simply change it to this:

local waittime = 5 -- Time Between each hit --'locals' are more efficient, and work faster with the script
local amnt = 4 --how much you get for it
local disabled=false
function onTouched(part)
    if disabled==false then --Proper debouncing method
        local h = part.Parent:findFirstChild("Humanoid")
        if (h~=nil) then
            local thisplr = game.Players:findFirstChild(h.Parent.Name)
            if (thisplr~=nil) then
                local stats = thisplr:findFirstChild("leaderstats")
                if (stats~=nil) then
                    local score = stats:findFirstChild("Points")
                    if (score~=nil) then
                        score.Value = score.Value + amnt
                        disabled=true
                    end
                end
            end
            script.Parent.Transparency = 1
            wait(waittime)
            script.Parent.Transparency = 0
            disabled=true
        end
    end
end

script.Parent.Touched:connect(onTouched)

It's almost fixed, but not completely. Add a new LocalScript into the StarterGui>Points>Frame>Point, and put this in the script:

local Player=game.Players.LocalPlayer
local stats=Plr:WaitForChild("leaderstats")
local points=stats:WaitForChild("Points")

function PointChange()
    script.Parent.Text="Points: "..points.Value
end

points.Changed:connect(PointsChange)

So, If you did this correctly, I believe it should now work.


Anyways, if you have any further problems/questions, please leave a comment below, and I'll see what I can do. Hope I helped :P

-Dyler3

0
But i think you understand me wrong, becouse still got normal leaderboard. I want make Points Leaderboard GUI. It should show me how many i have points in gui.I'll post link with screenshot. DevKarolus1 70 — 8y
0
Nevermind, i found mistake in your script that's why it didn't work, but fixed. Thanks for help :) DevKarolus1 70 — 8y
Ad

Answer this question