Player error in game

Ive been working on a goal scoring system, in the script that adds the points when a team scores, i wrote: local players = game:GetService(“Player”)
After a team scores, a remoteevent is fired, to make appear a gui that says Blue/Red Team has scored.

When i join the game to test it, I get this error: The current thread cannot create ‘Player’ (lacking capability WritePlayer)

I dont know what to do, if u could help me, i would appreciate it. Thank you.

Heres the script


local players = game:GetService("Player")


local scoreBoardGui = workspace.Soccer.ScoreBoard
local RedScore = scoreBoardGui.GuiRed.TextBox
local BlueScore = scoreBoardGui.GuiBlue.TextBox

local goalRed = workspace.Soccer.GoalDetectorRed
local goalBlue = workspace.Soccer.GoalDetectorBlue
local ball = workspace.Soccer.Ball
local originalposition = workspace.Soccer.BallPosition

local function score(team)
	team.Text = team.Text +1
	
	if score(team) == BlueScore then
		game.ReplicatedStorage.BlueScored:FireClient(players)
	elseif score(team) == RedScore then
		game.ReplicatedStorage.RedScored:FireClient(players)


	end 
	
	ball.Anchored = true
	ball.Position = originalposition.Position
	ball.AssemblyLinearVelocity = Vector3.new(0,0,0)
	ball.AssemblyAngularVelocity = Vector3.new(0,0,0)
	wait(1)
	ball.Anchored = false
end

ball.Touched:Connect(function(part)
	if part == goalRed then
		score(BlueScore)
		
	elseif part == goalBlue then
		score(RedScore)
	end
end)

FireClient is used to fire a remote event. Im not sure what exactly you are trying to accomplish here.

1 Like

You want to use :FireAllClients() instead of :FireClient(players)

if team == BlueScore then
	game.ReplicatedStorage.BlueScored:FireAllClients()
elseif team == RedScore then
	game.ReplicatedStorage.RedScored:FireAllClients()
end 

EDIT: Use team == BlueScore instead of score(team) == BlueScore.

1 Like

i doesnt work maybe the script thats in the gui is wrong


local players = game.Players.LocalPlayer
local GoalText = script.Parent.Frame.TextLabel
local Frame = script.Parent.Frame

game.ReplicatedStorage.BlueScored.OnClientEvent:Connect(players)
Frame.Visible = true
GoalText.Text = players.Name.." has scored"
wait(5)
Frame.Visible = false
local players = game.Players.LocalPlayer
local GoalText = script.Parent.Frame.TextLabel
local Frame = script.Parent.Frame

game.ReplicatedStorage.BlueScored.OnClientEvent:Connect(function()
   Frame.Visible = true
   GoalText.Text = players.Name.." has scored" --THis is only going to display the local players name, not the actual person who scored.
   wait(5)
   Frame.Visible = false
end)