Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Group rank for VIP to auto cash does not work?

This script does not work I think the problem is that I used for player in ipairs do and player:connect (function(function)

A problem only comes when I try add GetRankInGroup Script:

Wait(7)
	
vipamount = 4 -- This variable is the amount of RIX Vips will get each time.
amount = 2 -- This variable is the amount of RIX we will give each time.
timedelay = 2 -- (600)This variable is the amount of seconds in between each time the RIX is rewarded
currencyname = "RIX" -- This is the name of our Currency
groupId = 3141417 -- Group ID from the Group ranks will be taken from

while true do
	for _, player in ipairs(game.Players:GetPlayers()) do
		game.Player.PlayerAdded:connect(function(player)
			if player:FindFirstChild("leaderstats") then
				if player:GetRankInGroup(groupId) >= 50 then
					player.leaderstats.RIX.Value = player.leaderstats.RIX.Value + vipamount
				else
					player.leaderstats.RIX.Vaue = player.leaderstats.RIX.Value + amount
				end
			end
		end)
	end
end

2 comments

0

you crash your game by not waiting in your while loop. You create a PlayerAdded event every time the while loop runs, multiple times. (For EVERY player that's already in the game.) You gotta figure this out yourself..

0

I have been tried to make this script for a week now. Now I have it work. Thx.

1 answer

✓ Accepted answer

This script doesn't work because you are continuously running a while loop without yielding, and you are creating a new connection with each while loop iteration.

Try something more like this:

local Players = game:GetService("Players")
local VipAmount = 4 -- This variable is the amount of RIX Vips will get each time.
local Amount = 2 -- This variable is the amount of RIX we will give each time.
local TimeInterval = 2 -- (600)This variable is the amount of seconds in between each time the RIX is rewarded
local CurrencyName = "RIX" -- This is the name of our Currency
local GroupId = 3141417 -- Group ID from the Group ranks will be taken from

Players.PlayerAdded:Connect(function(Player)
	-- This connections runs upon a player joining the game

	local Stats -- Get their stats Object
	local AwardPerInterval -- Find out how much they should be awarded per interval

	local LeaderStats = Player:FindFirstChild("leaderstats")

	if LeaderStats then
		Stats = LeaderStats.RIX
		AwardPerInterval = Player:GetRankInGroup(GroupId) > 49 and VipAmount or Amount
	end

	local Total = Stats.Value

	while wait(TimeInterval) and Stats do
		-- Repeatedly wait the time interval
		-- Stop running once Stats is nil (when they leave)

		Total = Total + AwardPerInterval
		Stats.Value = Total
	end
end)

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