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

Not awarding XP when I touch the part?

Asked by 8 years ago
Edited 8 years ago

****Whenever the player finishes the obby they will step on a part which will award XP. But I made an error and I need help. I made EXP a number value so its not part of the leaderstats folder. So it would be player.EXP.Value instead of player.leaderstats.EXP.Value

1local Player = game.Players.LocalPlayer
2local Award = script.Parent
3local exp = Player.EXP
4 
5Award.Touched:connect(function(player)
6    if player and player.Parent and player.Parent:FindFirstChild('Humanoid') then
7        exp.Value = exp.Value + 15
8    end
9end)
0
I'm guessing this is a localScript inside of the workspace, and localScripts don't work there. Put the LocalScript in replicatedStorage theCJarmy7 1293 — 8y
0
The script is inside the part. FearlessAfrican 34 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

By writing for player.Parent you are referring to Players folder, and that's a mistake. You should also refer to the Player, and not the character.

Here is something I would prefer you use.

1script.Parent.Touched:connect(function(hit) -- This makes the function happen when the brick is touched
2    if game.Players:GetPlayerFromCharacter(hit.Parent) then -- The function GetPlayerFromCharacter refers to the Player, we use an if statement to makes sure it's a real player,
3        local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- A variable referring to the Player
4        if player:FindFirstChild("leaderstats") then -- Check if leaderstats exist
5            player.leaderstats.exp.Value = player.leaderstats.exp.Value + 15 --  increases the value
6        end
7        script.Parent:Destroy()  -- This is to remove the part that is touched, in case you don't want the player to touched again
8    end
9end)

The Character is the part of the player that is under the Player folder The Player is the part of the player that is under Workspace

0
Thanks! FearlessAfrican 34 — 8y
0
No problem :) chill22518 145 — 8y
Ad

Answer this question