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

Very simple script not responding?

Asked by
drew1017 330 Moderation Voter
9 years ago
function addxp(hit) 
    local dude = hit.Parent:WaitForChild('Character')
    dude.xp.Value = 1
    script.Parent:Destroy()
end

script.Parent.Touched:connect(addxp) -- the script's parent is a brick

Im 90% sure this should work, but when i touch the brick absolutely nothing happens. I checked the values after too, it remains at 0. Anything I did wrong?

3 answers

Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
9 years ago

If you are trying to access the player's Character, check if it has a Humanoid.

function addxp(hit) 
    local dude = hit.Parent:WaitForChild("Humanoid").Parent
    dude.xp.Value = 1
    script.Parent:Destroy()
end

script.Parent.Touched:connect(addxp)

or you can use the GetPlayerFromCharacter event.

function addxp(hit) 
    local dude = game.Players:GetPlayerFromCharacter(hit.Parent).Character -- accessing the player through the character
    dude.xp.Value = 1
    script.Parent:Destroy()
end

script.Parent.Touched:connect(addxp)
0
Worked perfectly, thanks! You're a very helpful member. drew1017 330 — 9y
0
Glad to help! woodengop 1134 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

You're leaving out some needed information. Is "xp" something in the character or in the leaderboards?

Anyway, I'll do both.

In character:

script.Parent.Touched:connect(function(hit)
    local dude = hit.Parent:WaitForChild("Humanoid").Parent --Wait for the humanoid, checking if "hit" is a character
    local xp = dude:WaitForChild("xp")
    xp.Value = 1
end)

In player:

script.Parent.Touched:connect(function(hit)
    local dude = hit.Parent:WaitForChild("Humanoid").Parent
    local player = game.Players:GetPlayerFromCharacter(dude)
    local leaderstats = player:WaitForChild("leaderstats")
    local xp = leaderstats:WaitForChild("xp")
    xp.Value = 1
end)

Hope this helps! :)

Log in to vote
-1
Answered by 9 years ago

There cannot be found thing such as Character. Character can be found from game.Players.Player.Character. You should also add the xp To Leaderboards, check out how to in wiki if you don't now: http://wiki.roblox.com/index.php?title=Leaderboards

function getxp(hit)
    for i,Player in ipairs(game.Players:GetPlayers()) do
        if hit.Parent = Player.Character then
        local Character = hit.Parent
        local Player = game.Players:GetPlayerFromCharacter(Character)
        Character.xp.Value = Character.xp.Value +1 --I made this like this, you can do like you want
        script.Parent:Destroy()
    end
end

script.Parent.Touched:connect(getxp)
0
Still didn't respond at all. drew1017 330 — 9y

Answer this question