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

Why the valor isnt part of workspace when it is created?

Asked by 6 years ago

I done a script when a player touch a block if he is in a determined team, the team will add a +1 to TeamA or B but when I touch the block it doesnt work. What can be the trouble?

local TeamA = Instance.new("NumberValue")
TeamA.Name = ("TeamA")
TeamA.Value = 0
TeamA.Parent = workspace

local TeamB = Instance.new("NumberValue")
TeamB.Name = ("TeamB")
TeamB.Value = 0
TeamB.Parent = workspace

script.Parent.Touched:connect(function(hit) --Get what made the hit.
    --Define player's variable here with the method GetPlayerFromCharacter!
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
    script.Parent.BrickColor = Player.TeamColor
    wait(.2) 

if Player.team == game.Teams.TeamA
    then
    game.Workspace.TeamA = game.workspace.TeamA.Value + 1
    Player.leaderboard.Painted.Value = Player.leaderboard.Painted.Value + 1
end

if Player.team == game.Teams.TeamB
    then
    game.workspace.TeamB = game.workspace.TeamB.Value + 1
    Player.leaderboard.Painted.Value = Player.leaderboard.Painted.Value + 1
    end


end)

0
Is the team in the player? therealae 7 — 6y

1 answer

Log in to vote
0
Answered by
OfcPedroo 396 Moderation Voter
6 years ago
Edited 6 years ago

I know what's going on.

A thing I learned recently: When there's a .Touched event, the LocalScript / Script NEEDS to be putted in the StarterGui. Other thing, I don't really like using NumberValues, I would recommend you using IntValues. Having said that, here's what you want:

local TeamA = Instance.new("IntValue") --Change to IntValue.
TeamA.Name = "TeamA" --Remove the ()
TeamA.Value = 0
TeamA.Parent = game.Workspace --Make sure he knows what's workspace.

local TeamB = Instance.new("IntValue") --Change to IntValue.
TeamB.Name = "TeamB" --Remove the ()
TeamB.Value = 0
TeamB.Parent = game.Workspace --Make sure he knows what's workspace.

script.Parent.Touched:connect(function(hit) --Get what made the hit.
    --Define player's variable here with the method GetPlayerFromCharacter!
    --local Player = game.Players:GetPlayerFromCharacter(hit.Parent): This works, but there's another way I prefer.

    local Character = hit.Parent.Name
    local Player = game.Players[Character]

    if hit.Parent:FindFirstChild("Humanoid") then --Check if it's a player.
            script.Parent.BrickColor = Player.TeamColor --In here you're saying Brick's Color should be the Player's TeamColor. I think what you want is the opposite. I didn't change that, but if what you want is CHANGE THE PLAYER'S TEAMCOLOR *TO* THE BRICK'S COLOR, then swap the variables there up.
            wait(.2)
    end

    if Player.Team == game.Teams.TeamA then
            game.Workspace.TeamA = game.Workspace.TeamA.Value + 1
            Player.leaderboard.Painted.Value = Player.leaderboard.Painted.Value + 1 --leaderboard? try like this, but if it won't work, switch 'leaderboard' with 'leaderstats'.

    elseif Player.Team == game.Teams.TeamB then
            game.Workspace.TeamB = game.Workspace.TeamB.Value + 1
            Player.leaderboard.Painted.Value = Player.leaderboard.Painted.Value + 1 --leaderboard? try like this, but if it won't work, switch 'leaderboard' with 'leaderstats'.
    end
end)

After 2 hours, here's your script there up ^^

If this solves your problem, please mark as the solution.

As always, good scripting!

0
thanks you HillsMaster 34 — 6y
0
np! ;D OfcPedroo 396 — 6y
0
but it didnt worked HillsMaster 34 — 6y
0
strange OfcPedroo 396 — 6y
0
course, you have to change the script.Parent on line 11. Remember, I said you have to put it in the StarterGui, so that and every script.Parent would change. OfcPedroo 396 — 6y
Ad

Answer this question