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)
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.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.