Making my first game (Soccer game)

image

The localscript currently contains this code.

local textbutton = game.StarterGui.ScreenGui.TextButton
textbutton.Activated:Connect(function()
		game.Players.LocalPlayer.Team = game.Teams.Red
       print("Firing")
end)

Also ignore the frame

chars chars

Alright, the problem.

Your getting the button from the StarterGui.
When the player joins, the GUI getā€™s cloned into their PlayerGUI.

Instead of the first line, do it like:

local textbutton = script.Parent.TextButton
textbutton.Activated:Connect(function()
		game.Players.LocalPlayer.Team = game.Teams.Red
       print("Firing")
end)

Quoted from GuiButton | Roblox Creator Documentation

MouseButton1Down(x: number, y: number): RBXScriptSignal
Fired when the mouse is in the left mouse down state on the GUI object.

However, for .Activated:

Activated(inputObject: InputObject, clickCount: number): RBXScriptSignal
Fires when the button is activated.

.Activated is a multi-platform event.

Thank you so much!

It works now. But I donā€™t understand why it works.

Why did it just work when you changed the variable reference?

MouseButton1Down still works for mobile devices that you mentioned that donā€™t work.

A lot of gameā€™s function with MouseButton1Down, and not Activated.

Alright, so.

The StarterGUI is where you, store GUIs, that the player getā€™s.
The GUIā€™s from StarterGUI get cloned into ā€œPlayerGUIā€ which is inside of the local player.

Check this out,
StarterGUI doc refrence

local textbutton = script.Parent.TextButton
textbutton.Activated:Connect(function()
		game.Players.LocalPlayer.Team = game.Teams.Red
       print("Firing")
end

So, basically the screengui gets cloned into the playerGUI and then using that to get the textbutton instead of directly referencing it.

1 Like

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