Script not working, but giving no errors?

Hi.

So I have this script that gives a player 1 point whenever they score a goal, but it isn’t working. When I looked in the output I saw no errors.

Here is the script:

local teams = game:GetService("Teams")


local goal1 = game:GetService("Workspace").Map.goal2
local goal2 = game:GetService("Workspace").Map.goal1
local ball = game:GetService("Workspace"):WaitForChild("TPS")
local rs = game:GetService("ReplicatedStorage")
local me = rs:WaitForChild("Message")

local Kick = true




function onGoal()
ball.Touched:Connect(function(part)
	if part == goal1 == true and teams.Bayern and teams.GKB == false then
			local Scorer = game:GetService("Workspace"):WaitForChild("TPS").Owner.Value

			local Scorer_Name = Scorer.Name
			local Message = string.upper(Scorer_Name).." SCORED!"

		
		me:FireAllClients(Message)
		Scorer.leaderstats.Goals.Value = Scorer.leaderstats.Goals.Value +1
		
		
	

		task.wait(12)
		Kick = false

	elseif part == goal2 == true and teams.Milan and teams.GKM == false then
			local Scorer = game:GetService("Workspace"):WaitForChild("TPS").Owner.Value

			local Scorer_Name = Scorer.Name
			local Message = string.upper(Scorer_Name).." SCORED!"

		
		me:FireAllClients(Message)
		Scorer.leaderstats.Goals.Value = Scorer.leaderstats.Goals.Value +1
	

		task.wait(12)
		Kick = false
end
end)
end

im confused why ur ball.Touched function is inside a funtion named onGoal() and when is that fired?

1 Like

when the ball touches a part, it fires.

Try this still:

local teams = game:GetService("Teams")


local goal1 = game:GetService("Workspace").Map.goal2
local goal2 = game:GetService("Workspace").Map.goal1
local ball = game:GetService("Workspace"):WaitForChild("TPS")
local rs = game:GetService("ReplicatedStorage")
local me = rs:WaitForChild("Message")

local Kick = true




	ball.Touched:Connect(function(part)
		if part == goal1 and teams.Bayern and teams.GKB == false then
			local Scorer = game:GetService("Workspace"):WaitForChild("TPS").Owner.Value

			local Scorer_Name = Scorer.Name
			local Message = string.upper(Scorer_Name).." SCORED!"


			me:FireAllClients(Message)
			Scorer.leaderstats.Goals.Value = Scorer.leaderstats.Goals.Value +1




			task.wait(12)
			Kick = false

		elseif part == goal2 and teams.Milan and teams.GKM == false then
			local Scorer = game:GetService("Workspace"):WaitForChild("TPS").Owner.Value

			local Scorer_Name = Scorer.Name
			local Message = string.upper(Scorer_Name).." SCORED!"


			me:FireAllClients(Message)
			Scorer.leaderstats.Goals.Value = Scorer.leaderstats.Goals.Value +1


			task.wait(12)
			Kick = false
		end
	end)

Now I get the error, attempted to index with name

ur Touched function was inside another function which was never fired so i took it out. now the code is running and thats why u even can see the errors now

So what does the error attempt to index nil with name mean? I have never gotten this error using object values

where does it error in the script

local Scorer_Name = Scorer.Name

it looks like the Workspace.TPS.Owner.Value is nil so it has no value and when u try to get nils name it errors

I use Workspace.Tps.Owner.Value for my network ownership script though.

but what is the value? and when do u change that value?

That value is the players name that has the ball, i can give you the network ownership script if you want.

u never set it to players name in this script

No, I am using another script for that. Here is the script:

local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("ChangeOwner")
local Event2 = RS:WaitForChild("ChangeValue")

Event.OnServerEvent:connect(function(player, ball)

	local Distance = player.Character.HumanoidRootPart.Position.Magnitude - ball.Position.Magnitude
	if ball.Name ~= "TPS" then return end
	if game:GetService("Workspace"):WaitForChild("TPS" , math.huge).Anchored == true then return end
	if Distance > 10 then return end
	if ball.Owner.Value ~= player then
		ball:SetNetworkOwner(player)

		ball.Owner.Value = player
		ball.ReactDecline.Value = true
		local Bubble = Instance.new("Part")
		Bubble.Shape = "Ball"
		Bubble.Position = ball.Position
		Bubble.Name = "ReactBubble"
		Bubble.CanCollide = false
		Bubble.Anchored = true
		Bubble.Transparency = 0.849
		Bubble.BrickColor = BrickColor.new("Really black")
		Bubble.BrickColor = player.TeamColor
		Bubble.Size = Vector3.new(2,2,2)
		Bubble.Parent = workspace
		wait(0.8)
		ball.ReactDecline.Value = false
		Bubble:Destroy()
	end
end)

Event2.OnServerEvent:connect(function(player, ball)
	
	if game:GetService("Workspace"):WaitForChild("TPS" , math.huge).Anchored == true then return end
	ball.Ankle.Value = true
	wait(0.5)
	ball.Ankle.Value = false
end)
if game:GetService("Workspace"):WaitForChild("TPS" , math.huge).Anchored == true then return end

so this is a working script no errors?

Yes this script is working, with no errors.

is this stringvalue or objectvalue

This is an object value, not a string balue.

for some reason when u try to set Scorer to a player, the Owner.Value is nil and after that u try to get the nils name