local replicated = game.ReplicatedStorage
local remote = replicated.Events.ChangeTeam
-- teams brickcolors
local cicolor = 'Cocoa'
local mdcolor = 'Magenta'
local smdcolor = 'Navy blue'
local sqcolor = 'Bright red'
local tscolor = 'Deep orange'
-- teams buttons
local frame = script.Parent
local cibutton = frame.citeam
local mdbutton = frame.mdteam
local smdbutton = frame.smdteam
local sqbutton = frame.sqteam
local tsbutton = frame.tsteam
mdbutton.MouseButton1Click:Connect(function(plr)
if plr:GetRankInGroup(6057034) >= 3 then
remote:FireServer(BrickColor.new(mdcolor))
end
end)
cibutton.MouseButton1Click:Connect(function(plr)
if plr:GetRankInGroup(6789012) >= 2 then
remote:FireServer(BrickColor.new(cicolor))
end
end)
smdbutton.MouseButton1Click:Connect(function(plr)
if plr:GetRankInGroup(9896154) >= 2 then
remote:FireServer(BrickColor.new(smdcolor))
end
end)
sqbutton.MouseButton1Click:Connect(function(plr)
if plr:GetRankInGroup(10862893) >= 1 then
remote:FireServer(BrickColor.new(sqcolor))
end
end)
tsbutton.MouseButton1Click:Connect(function(plr)
remote:FireServer(BrickColor.new(tscolor))
end)
Output - Attempt to index nil with GetRankInGroup
Many thanks if you help me solving my issue.
local players = game:GetService("Players")
local plr = players.LocalPlayer or players.PlayerAdded:Wait()
local replicated = game.ReplicatedStorage
local remote = replicated.Events.ChangeTeam
-- teams brickcolors
local cicolor = 'Cocoa'
local mdcolor = 'Magenta'
local smdcolor = 'Navy blue'
local sqcolor = 'Bright red'
local tscolor = 'Deep orange'
-- teams buttons
local frame = script.Parent
local cibutton = frame.citeam
local mdbutton = frame.mdteam
local smdbutton = frame.smdteam
local sqbutton = frame.sqteam
local tsbutton = frame.tsteam
mdbutton.MouseButton1Click:Connect(function()
if plr:GetRankInGroup(6057034) >= 3 then
remote:FireServer(BrickColor.new(mdcolor))
end
end)
cibutton.MouseButton1Click:Connect(function()
if plr:GetRankInGroup(6789012) >= 2 then
remote:FireServer(BrickColor.new(cicolor))
end
end)
smdbutton.MouseButton1Click:Connect(function()
if plr:GetRankInGroup(9896154) >= 2 then
remote:FireServer(BrickColor.new(smdcolor))
end
end)
sqbutton.MouseButton1Click:Connect(function()
if plr:GetRankInGroup(10862893) >= 1 then
remote:FireServer(BrickColor.new(sqcolor))
end
end)
tsbutton.MouseButton1Click:Connect(function()
remote:FireServer(BrickColor.new(tscolor))
end)
I understand that on the client, local scripts are run while the game is still loading, but is it really so unclear that the client (LocalPlayer) has to load itself first so core scripts would work? (core scripts are loaded before local scripts)