Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I can't hide or destroy a gui with filteringenabled on???

You see, I've been making a main menu gui and the teleporting works and team changing etc. However, when I try to hide the gui so the player can actually play, it doesn't do anything. My local script is inside the gui so I figured that if I try hide the gui it'll also disable the script that lets the team changing script work. I'm not exactly sure where to place my local script either as filteringenabled doesn't let you use LocalPlayer. I'll provide the scripts. Local Script:

local event = game:GetService("ReplicatedStorage"):WaitForChild("StartMenu")
script.Parent.MouseButton1Down:connect(function()
	game.ReplicatedStorage.StartMenu:FireServer() --StartMenu is a RemoteEvent.
end)

Normal Script (located in serverscriptservice):

local event = game:GetService("ReplicatedStorage"):WaitForChild('StartMenu')
event.OnServerEvent:connect(function(player)
	print("Someone pressed the button!")
	player.TeamColor = BrickColor.new("Persimmon")
	player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(15.31,85.839,32.044))
	player.Character.Humanoid.JumpPower = 50
	player.Character.Humanoid.WalkSpeed = 16
    player.PlayerGui.MenuStart.Enabled = false --Renamed to avoid confusion.
end)

2 answers

✓ Accepted answer

The server cannot access a UI, because a UI is on the computer (client) and the server is in the roblox's server. The roblox's server is not your computer. You should put the script that changes the UI in a localscript.

2 comments

0

If I put it in a localscript I'd get the error 'OnServerEvent can only be used on the server'.

0

No, the editing the UI part, not the rest of script. Can you please make a little common sense?

The argument player is just a string. Try this:

local event = game:GetService("ReplicatedStorage"):WaitForChild('StartMenu')
event.OnServerEvent:connect(function(plr)
    local player = game:GetService("Players"):FindFirstChild(plr) -- Look for player with the name in plr

    player.TeamColor = BrickColor.new("Persimmon")
    player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(15.31,85.839,32.044))
    player.Character.Humanoid.JumpPower = 50
    player.Character.Humanoid.WalkSpeed = 16
    player.PlayerGui.MenuStart.Enabled = false --Renamed to avoid confusion.
end)

2 comments

0

OnServerEvent passes the player object as the first arg, it is not a string.

0

@kingdom5, Well, My bad, got confused.

This discussion is preserved as it was. New answers, comments, and votes are closed.