Text isn't changing

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? When a player goales it should say “Somebody goaled”

  2. What is the issue? it doesn’t change the text when its goaled

local ball = game.Workspace.Ball
local goal = game.Workspace.Part1


local function onCollisionEnter(part)
	if part == goal then
		game.StarterGui.ScreenGui.TextLabel.Text = "Goaled"
		print("Goal!")
		
	end
end


ball.Touched:Connect(onCollisionEnter)


There are many problems with this code, but the main error is that you’re modifying the value in StarterGui.

Sorry, am new to scripting. What do you mean by that

You cannot change the text in a starterGui like that, you should fire a remote event and then change the text through a local script. By doing it this way you are changing the text on the server and not on the client.

I dont know how to use remote events right now.

You should really learn about them, they are crucial for client-server and server-client communications
Here are the docs and a video explaining how they work:
docs: RemoteEvent | Roblox Creator Documentation
video: Advanced Roblox Scripting Tutorial #8 - Remote Events & Remote Functions (Beginner to Pro 2019) - YouTube

1 Like

It means that you’re actually changing the text that is in StarterGui. It is only replicated once (when the player joins/resets).
To fix this, you can either fire a RemoteEvent to change it from the client, or connect to the Players.PlayerAdded event, and then use the given Player object to change their UI individually from there.

game:GetService("Players").PlayerAdded:Connect(function(plr)
	goal.Touched:Connect(function(otherPart)
		if otherPart == ball then
			plr.PlayerGui.ScreenGui.TextLabel.Text = "Goaled"
		end
	end)
end)

Thanks for telling me, Ur script is easier to understand,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.