I wrote some code but it doesn’t work the way I want
The code I wrote is as follows:
local plr = game.Players.LocalPlayer
local gui = script.Parent
local Open = "!egitimyap1"
plr.Chatted:Connect(function(msg)
if plr:GetRankInGroup(15254328) > 254 then
if msg == Open then
gui.Visible = true
wait(10)
gui.Visible = false
end
end
end)
What I want is this, when I type !egitimyap1, the gui that will open should be opened for everyone.
Hey @LeadersTR, Use a normal script for this, not a local script, To change the gui you will have to use RemoteEvent which will open the gui for the player
local Open = "!egitimyap1"
local gui = script.Parent
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if plr:GetRankInGroup(15254328) > 254 then
if msg == Open then
print("Test")
gui.Visible = true
wait(10)
gui.Visible = false
end
end)
end)
As you said, I changed the script code to normal script instead of local, and created a remote event in the serverstorage section, but this time the gui did not open at all.
Alternatively, you can try this way, but I don’t know if the plr.Chatted event will work, because when I tested on a local script this chatted wouldn’t work
Example:
local Players = game:GetService("Players")
local function onPlayerAdded(player)
local function onChatted(message)
-- do stuff with message and player
print(message)
end
player.Chatted:Connect(onChatted)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Example2:
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local teamPlaying = Teams.Playing
local teamSpectators = Teams.Spectating
local playCommand = "/play"
local function play(player)
player.Team = teamPlaying
player.TeamColor = teamPlaying.TeamColor
-- Respawn the player (moves them to spawn location)
player:LoadCharacter()
end
local function onPlayerDied(player, _character)
-- When someone dies, put them on the spectator team
player.Team = teamSpectators
end
local function onPlayerSpawned(player, character)
local human = character:WaitForChild("Humanoid")
human.Died:Connect(function()
onPlayerDied(player, character)
end)
end
local function onPlayerChatted(player, message)
if message:sub(1, playCommand:len()):lower() == playCommand then
play(player)
end
end
local function onPlayerAdded(player)
if player.Character then
onPlayerSpawned(player, player.Character)
end
player.CharacterAdded:Connect(function()
onPlayerSpawned(player, player.Character)
end)
player.Chatted:Connect(function(message, _recipient)
onPlayerChatted(player, message)
end)
end
for _, player in pairs(Players:GetPlayers()) do
onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)