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

Why is this not working When I touch a brick? (Inside A script)

Asked by 6 years ago
db = false
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if not db then
            db = true
            script.Parent.BrickColor = BrickColor.new("Bright red")
            local plr = player.name 
            game.ServerStorage.PlayerMoney.plr.Value = game.ServerStorage.PlayerMoney.plr.Value + 10
            wait(3)
            script.Parent.BrickColor = BrickColor.new("Bright green")
            db = false
        end
    end
end)

2 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

on line 8 where you make the variable "plr" You never use it later on.

If you are trying to find a child in PlayerMoney with the name of the players name you should do

local plr = player.Name
game.ServerStorage.PlayerMoney:FindFirstChild(plr).Value = game.ServerStorage.PlayerMoney:FindFirstChild(plr).Value + 10
Ad
Log in to vote
1
Answered by
Async_io 908 Moderation Voter
6 years ago

I agree with PoePoeCannon's answer, but I'll explain it a little bit more.

game.ServerStorage.PlayerMoney.plr.Value = game.ServerStorage.PlayerMoney.plr.Value + 10 isn't a valid command. if you're trying to find something by using a changing-name. (i.e. player name) you should use [] instead of a period. If this doesn't make since, then this might

game.ServerStorage.PlayerMoney[plr].Value = game.ServerStorage.PlayerMoney[plr].Value + 10

Answer this question