Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Aspiring devloper has problems with a script. Any ideas?

Asked by 2 years ago

inside a p:art called "Spirit" there are two scripts:

one Supposedly should give EXP when touched by the "WaterEssence":

P.D.: "EXP" is in a folder named "leaderstats" inside the character

local ATM = script.Parent

ATM.Touched:connect(function(entity)

     print(entity:GetFullName())

    if entity.Parent.Name == "WaterEssence" then


        local Man =  entity.Parent.Parent.Parent
        local RealMan = game.Players:GetPlayerFromCharacter(Man)
        local Bro = RealMan.FindFirstChild("leaderstats")
        local EXP = RealMan.Bro:FindFirstChild("EXP") 
         EXP.Value = EXP.Value + 100
         print(EXP.Value)
         wait(1)                  
     end
 end)

the other one just makes it invisible.

script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Name == "WaterEssence" then
    script.Parent.Transparency = 0.5
    wait(20)
    script.Parent.Transparency = 0
  end
end)

the invisible script works fine, but the other one shows this error:

error: Workspace.Spirit.Script:12: attempt to index local 'RealMan' (a nil value)

if you dont have any ideas, please give me an alternative way to do it.

Thanks to everyone, SuVee, Aspiring Dev

0
If a player's limb is hitting it, then the Man should equal entity.Parent TdaGreat04 76 — 2y
0
no, a handle from a tool is hitting it. SuperBeeperman 30 — 2y
0
I see the problem, and it is trying to get the player. I'll try to use another way to get the player and show you it. 522049 152 — 2y

1 answer

Log in to vote
1
Answered by
522049 152
2 years ago
Edited 2 years ago
local ATM = script.Parent

ATM.Touched:connect(function(entity)

     print(entity:GetFullName())

    if entity.Parent.Name == "WaterEssence" and game.Players:FindFirstChild(entity.Parent.Parent.Name) then


       -- local Man =  entity.Parent.Parent.Parent
        local RealMan = game.Players:FindFirstChild(entity.Parent.Parent.Name)
        local Bro = RealMan:FindFirstChild("leaderstats")
        local EXP = Bro:FindFirstChild("EXP") 
         EXP.Value = EXP.Value + 100
         print(EXP.Value)
         wait(1)                  
     end
 end)
0
I also fixed some possible errors in your script. 522049 152 — 2y
0
Thanks! this worked! now you have more reputation! ;) SuperBeeperman 30 — 2y
Ad

Answer this question