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
1function addxp(hit)
2    local dude = hit.Parent:WaitForChild('Character')
3    dude.xp.Value = 1
4    script.Parent:Destroy()
5end
6 
7script.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.

1function addxp(hit)
2    local dude = hit.Parent:WaitForChild("Humanoid").Parent
3    dude.xp.Value = 1
4    script.Parent:Destroy()
5end
6 
7script.Parent.Touched:connect(addxp)

or you can use the GetPlayerFromCharacter event.

1function addxp(hit)
2    local dude = game.Players:GetPlayerFromCharacter(hit.Parent).Character -- accessing the player through the character
3    dude.xp.Value = 1
4    script.Parent:Destroy()
5end
6 
7script.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:

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

In player:

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

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

01function getxp(hit)
02    for i,Player in ipairs(game.Players:GetPlayers()) do
03        if hit.Parent = Player.Character then
04        local Character = hit.Parent
05        local Player = game.Players:GetPlayerFromCharacter(Character)
06        Character.xp.Value = Character.xp.Value +1 --I made this like this, you can do like you want
07        script.Parent:Destroy()
08    end
09end
10 
11script.Parent.Touched:connect(getxp)
0
Still didn't respond at all. drew1017 330 — 9y

Answer this question