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 make this script work for certain group role 3+, just for all members?

My script adds 1 point into a player leaderstat every 1 minute if they are in a group. I have tried but I cannot seem to get it to only give it if they are rank number 3 or higher. Can someone please help? Here is the script:


local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
	
	local leader = Instance.new("Folder",player)
	leader.Name = "leaderstats"
	
	local currency = Instance.new("IntValue",leader)
	currency.Name = "Points"
	currency.Value = ds:GetAsync(player.UserId)
	
	ds:SetAsync(player.UserId, currency.Value)

	currency.Changed:connect(function()
		ds:SetAsync(player.UserId, currency.Value)
	end)
end)

game.Players.PlayerRemoving:connect(function(player)
	
	ds:SetAsync(player.UserId, player.leaderstats.Points.Value)
	
end)

game.Players.PlayerAdded:connect(function(Player)
	wait(2)
	while true do wait(60) -- Time between giving points
		if Player:IsInGroup(3992679) then -- Group ID here
			Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + 1
		end
	end
end)

1 comment

0

Shouldn't you like make this script separate in serverscriptservice I suggest make it separate then trying again

1 answer

✓ Accepted answer

Change line 29 Player:IsInGroup(ID) to Player:GetRankInGroup(ID) >= 3

IsInGroup returns a bool value if they're in the specified group. GetRankInGroup returns a number of the rank of the player in the group. You can use that number to check it's greater than a number, and if it is, then do the rest of the code.

1 comment

0

Thanks! This helped.

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