Hey there!
I’m Shark, and I need help.
So, I’m not the best at scripting, but I try my best.
I need help with this script, basically, what I need it to do is : When you type the word “!startrules” in the chat, a GUI will become visible and it will display what I have on it and when you say the word “!stoprules” the GUI will become invisible. But for some reason, it doesn’t seem to work.
Sorry if I’ve done something wrong, but here’s my script.
local GroupId = 8266373
local MinimumRank = 252
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if Player:GetRankInGroup(GroupId) >= MinimumRank then
if Message == "!startrules" then
game.StarterGui.Rules.Rule1.Visible = true
elseif Message == "!stoprules" then
game.StarterGui.Rules.Enabled = false
end
end
end)
end)
I would really appreciate some help, if someone could help me fix it, it would be appreciated and once again, apologies if I have done something wrong.
Thank you.
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message, plr)
if plr:GetRankInGroup(GroupId) >= MinimumRank then
if Message == "!startrules" then
game.StarterGui.Rules.Rule1.Visible = true
elseif Message == "!stoprules" then
game.StarterGui.Rules.Enabled = false
end
end
end)
end)
And another thing, when you add it in local script, you should do game:GetService(“Players”).LocalPlayer.PlayerGui instead of game:GetService(“StarterGui”) because the PlayerGui the player has is the current GUI that is shown to them
You’re using StarterGui rather than the GUI located in the Player, StaterGui should only be changed if you want to change something for everyone after a respawn since it gets replicated, but in this case, you only have to change it for a single player, so PlayerGui is what you need to use. Keep the code in a regular script but change it to this
local GroupId = 8266373
local MinimumRank = 252
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if Player:GetRankInGroup(GroupId) >= MinimumRank then
if Message == "!startrules" then
Player.PlayerGui.Rules.Rule1.Visible = true
elseif Message == "!stoprules" then
Player.PlayerGui.Rules.Enabled = false
end
end
end)
end)
This wouldn’t work, even if this was in a local script the game would have FE enabled so the things 1 local script does wouldn’t replicate to the other players
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message, plr)
if plr:GetRankInGroup(GroupId) >= MinimumRank then
if Message == "!startrules" then
for i, v in pairs(game.PLayers:GetChildren()) do
v:FindFirstChild("PlayerGui").StarterGui.Rules.Visible = true
end
elseif Message == "!stoprules" then
for i, v in pairs(game.PLayers:GetChildren()) do
v:FindFirstChild("PlayerGui").StarterGui.Rules.Visible = false
end
end
end
end)
end)