Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help me please! How to do it? (value). HELP!!!!!llllllllllllllllll

I want to make that after counting all the players threw for one team. I made the count in another script and the problem is not this. The problem in this -----------------------------------------ServerScriptService.Script:4: attempt to index local 'player' (a nil value)

The script itself

local player = game.Players.LocalPlayer

if game.Workspace.NYGNO.BrickColor == BrickColor.new("Lily white") then player.TeamColor = BrickColor.new("Forest green") end

Where is the script

ServerScriptService
Script

2 comments

0

A normal script can't get the LocalPlayer, only client-sided scripts can

0

you would have to get the player from some event, like touched

1 answer

A normal Script doesn't use LocalPlayer (only LocalScript does). You have to use another method to get the player. Here are some ideas what you can get player from:

I. 'Touched' event. This event fires, when player touches given part, for example:

script.Parent.Touched:connect(function(hit) -- Hit is a part of character which actually touched the part (left leg, head, right arm etc.)
    local player = hit.Parent -- Here's the player :)
    -- Do anything you want.
end)

II. Player joining the game. Event 'PlayerAdded' fires whemever any player joins the game:

game:GetService("Players").PlayerAdded:connect(function(player) -- Player is actually here, you don't need to write a variable :)
    -- Do anything you want here
end)

I hope I helped :D

This discussion is preserved as it was. New answers, comments, and votes are closed.