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

Script is supposed to add 1 values to the leaderstats: "Points", but it dosent. Help?

Asked by 4 years ago
Edited 4 years ago

so what this script does is find a tool called "Tape" and when it collides with the part, it adds 1 to the "Points" value in the leaderstats. however, despite NO ERRORS IN OUTPUT, AND WITH EVERYTHING SPELLED CORRECTLY, the script dosent work, please help!

script.Parent.Touched:connect(function(p)
if p.Parent.Name == "Tape" then 
amnt = 2    
    local h = game.Workspace: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

end
end)

this script is located inside workspace inside a model inside a part, so if you wanted to go to workspace, It would be script.Parent.Parent.Parent

0
Try to use :FindFirstChild() instead of :findFirstChild() . It works the same way too. And also your leaderstats might be named wrong. 123nabilben123 499 — 4y
0
like i said, all spelling was correct, i tried this tihng, but with already existing methods that i knew worked, instead of attempting this. Adenandpuppy 87 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

This answer was modified for Adenandpuppy based on information not given in the post.

Your issue is you do not know how to find "Humanoid", or more specifically, the player that must be rewarded for placing tape in contact of your touching part. Here are two ways I suggest going about fixing your issue:

  • Solution 1

You stated the player is using a tool that drags "Tape" around, this means you should be able to tag "Tape" with an identifier that your touching part can use for rewarding. I suggest putting in a StringValue with a value of the players name, using the grabbing tool to find the player. Using this, you would remove your humanoid check in your code and find the player through game.Players:FindFirstChild(StringValue.Value)

  • Solution 2

I would guess that the sort of game you make would have some based owned by the player where they are moving "Tape" onto some collector? If this is true, you could have an owner value in reach of the touching part to reward that owner every time "Tape" touches it.

I am sorry I cannot offer any more information or a more precise solution, but given the information provided, this is all I can do!

0
Problem: The tool never is eqqupiied. it is dragged around by a grab tool, which is eqquiped. Adenandpuppy 87 — 4y
Ad

Answer this question