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

Can anyone help me?

Asked by 8 years ago
local player = {}
function touchmebaby(hit)
    if hit.Parent:findFirstChild("Humanoid") then
        local x = {}
        local q = {game.Players}
        for i, v in pairs(q):GetChildren() do
            table.insert(x, "v.Name")
            if v.Name == hit.Parent then
                if v.leaderstats.Value == 1 then 
                v.leaderstats.Value =2 
            end
            end
    end
        elseif hit.Parent.Parent.leaderstats.Level.Value < 2 then
        return
    end
end

script.Parent.Touched:connect(touchmebaby)

I want to get the player from the character after stepping on the part .-.

2 answers

Log in to vote
3
Answered by 8 years ago

A couple of mistakes, you need to read more about iteration and the use of tables.

Fixed script

function touchmebaby(hit)
    if hit.Parent:findFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- There is a function, GetPlayerFromCharacter(), pretty self-explanatory
        if player.leaderstats.Value == 1 then 
            player.leaderstats.Value = 2 
        end
    end
end

script.Parent.Touched:connect(touchmebaby)

You had tables, and things that you did not even need, this script is way simpler and works properly, you need to think of the simplest way to accomplish what you want, it's way easier, faster, and way more efficient.

Hope this helps!

0
Ah, that will work better than mine, faster, but I think the leaderstats value is an int? Wouldn't it be better to increment it like: player.leaderstats.Value = player.leaderstats.Value + 1? Xetrax 85 — 8y
0
It doesn't really matter, since you're only changing the value only if it's at 1. AbsoluteAxiom 175 — 8y
Ad
Log in to vote
1
Answered by
Xetrax 85
8 years ago

I believe one error is right in Line 07, you referenced the string path for the player's name, which will always end up in your table as "v.Name", just take away the quotes around v.Name; And again, another error is right in Line 10, if you want to increment an INT value, which is what I'm guessing this value to be, always write it like: v.leaderstats.Value = v.leaderstats.Value + 1, which will increment the value by 1. The last error I see is on line 14, you're trying to reference the leaderstats in the Workspace(?), you don't want to do this, instead do it like: elseif game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Value < 2 then return end (Which I might add makes no sense, as it will always return and never give them a point... Also, I now see one last error, you wrote your q table like the Players are an object, not correctly getting all the members of Players, write tables like this in the future like so: q = game.Players:GetChildren() which will get every player in Players and store them in the table.

Answer this question