Script error support

Hey! I’m not so good in scripting so I need help with scripting. I’m making game and I need ranks in leaderboard but I have errors with it.

-- my script
game.Players.PlayerAdded:Connect(function(player)
	if game.Players.ItzCrime_bruh.Team["Combine Unit"] then game.Players.ItzCrime_bruh.leaderstats.Rank = "Recruit"
-- leaderstats script
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"

	local Rank = Instance.new("IntValue", leaderstats)
	Rank.Name = "Rank"
	Rank.Rank = ""

end)

(Please review my scripts and help me with it)

2 Likes

In my game 2 teams, “Combine Unit” and “Citizen” (Citizen must have rank “Citizen” and Combine Unit must have rank “Recruit”)

1 Like

.Rank is not a property of an intvalue, i think you should refer to Rank.Value

1 Like

In that case use a stringvalue instead, so you can assign a string to represent each rank

1 Like

Now what do I do with my script to assign specific rank to specific team?

You don’t nees two script for it and you are trying to use a IntValue as a StringValue. Try this:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"

	local Rank = Instance.new("StringValue", leaderstats)
	Rank.Name = "Rank"

	if player.Team == "Combine Unit" then
		Rank.Value = "Recruit"
	elseif player.Team == "Citizen" then
		Rank.Value = "Citizen"
	end
end)
1 Like

And one thing to note i reccomend you dont use the parent argument in the Instance.new() constructor, as it is slower to initialize than regularly parenting at the bottom

1 Like

I forgot to remove a useless line but I already fixed it.

Remade script in some parts but still it won’t work, in what problem?

-- leaderstats script
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"

	local Rank = Instance.new("StringValue", leaderstats)
	Rank.Name = "Rank"


	if player.Team == "Combine Unit" then
		Rank.Value = "Recruit"
	elseif player.Team == "Citizen" then
		Rank.Value = "Citizen"
	elseif player.Team == "Loading" then
		Rank.Value = "-"
	end
end)

Video dont show leaderboard o_o

1 Like

It dont show rank in leaderboard, it shows like " ". What do I do now?

1 Like

oh, you are trying to change teams with button, it won’t work then. Try this instead:
You will need to create a RemoteEvent in ReplicatedStorage

-- leaderstats script
game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"

	local Rank = Instance.new("StringValue", leaderstats)
	Rank.Name = "Rank"
	Rank.Value = "-"
	
	player.Team = game.Teams.Loading
end)

-- event script
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, rank)
	if typeof(rank) == "string" then
		if rank == "Combine Unit" then
			player.Rank.Value = "Combine Unit"
			player.Team = game.Teams["Combine Unit"]
		elseif rank == "Citizen"
			player.Rank.Value = "Citizen"
			player.Team = game.Teams.Citizen
		end
	else
		print("["..rank.."] Is not a String")
	end
end)

LocalScript inside the button:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer(script.Parent.Text)
end)

Where do I place event script then?

1 Like

I placed event script inside ServerScriptService, when I’m changing teams it dont show rank it shows “-” (Local script is inside both buttons)

show me a picture of your explorer

1 Like

Heres explorer:
65rsCtm

can u show me both ResetScript and TeamChange pls

1 Like

in reset scripts its like if you click on button you die to apply changes on character, team change changes your team

-- reset script
function onButtonClicked()
script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health = 0
end

script.Parent.MouseButton1Click:connect(onButtonClicked)
-- team change for citizen
function Click(mouse)
script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("White")
end


script.Parent.MouseButton1Down:connect(Click)

-- team change for combine unit
function Click(mouse)
script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Maroon")
end


script.Parent.MouseButton1Down:connect(Click)

i guess theres no matter between them, they are just to apply new things on your player

1 Like

Ok, so you didn’t added a RemoteEvent to ReplicatedStorage so add it and delete TeamChange and ResetScript and change LocalScript to:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer(script.Parent.Text) -- this changes player team and rank
	game.Players.LocalPlayer.Character.Humanoid.Health = 0
end)

you don’t need to change it name