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

local Player = game.Players.LocalPlayer
local Award = script.Parent
local exp = Player.EXP

Award.Touched:connect(function(player)
    if player and player.Parent and player.Parent:FindFirstChild('Humanoid') then
        exp.Value = exp.Value + 15
    end
end)
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.

script.Parent.Touched:connect(function(hit) -- This makes the function happen when the brick is touched
    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, 
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- A variable referring to the Player
        if player:FindFirstChild("leaderstats") then -- Check if leaderstats exist
            player.leaderstats.exp.Value = player.leaderstats.exp.Value + 15 --  increases the value
        end
        script.Parent:Destroy()  -- This is to remove the part that is touched, in case you don't want the player to touched again
    end
end)

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