This script doesnt give the player rock

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want this script to give the player new rock if the value changed

  1. What is the issue? Include screenshots / videos if possible!

It doesnt work at all

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried adding while task.wait() do, but when i did that, it worked, but it gave the player tons of same rocks

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

task.spawn(function()
	for _, player in pairs(game.Players:GetPlayers()) do
		local rock = player.leaderstats:WaitForChild("rock")
		rock.Changed:Connect(function(value)
			local therock = value.." rock"
			for _, currentrock in pairs(game.ServerStorage.rocks:GetChildren()) do
				if currentrock.Name == therock then
					local char = player.Character or player.CharacterAdded:Wait()
					for _, delete in pairs(char:GetChildren()) do
						if delete.Name ~= therock and delete:IsA("Tool") then
							delete:Destroy()
						end
					end

					for _, delete2 in pairs(player.Backpack:GetChildren()) do
						if delete2.Name ~= therock and delete2:IsA("Tool") then
							delete2:Destroy()
						end
					end

					for _, delete3 in pairs(player.StarterGear:GetChildren()) do
						if delete3.Name ~= therock and delete3:IsA("Tool") then
							delete3:Destroy()
						end
					end

					local clonedtool = currentrock:Clone()
					clonedtool.Parent = player.Backpack
					local clonedtool2 = currentrock:Clone()
					clonedtool2.Parent = player.StarterGear
				end
			end
		end)
	end
end)

Thanks.

First, I recommend using the game.Players.PlayerAdded event (if this is a server script, then most likely it is loaded before the player joined and does not have time to iterate through players)
Secondly, are there any errors? Perhaps you are missing something in ServerStorage

Sorry that i didnt respond for long, 1. okay i will try that and 2. no there isn’t any

It worked! thanks! now I can get admin rocks to work

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.