Script Refuses to Clone Children to Backpack!

  1. What do you want to achieve? Keep it simple and clear!
    I want to clone tools from the replicated storage to the backpack by confirming the name with an object value in leaderstats.

  2. What is the issue? Include screenshots / videos if possible!
    When I test the game, I get no errors, however, the tools that were meant to be duplicated because of the object value in players are not in my backpack.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have spent weeks surfing the web for a solution, but it seems not many people are using an object value in players to clone the children of a part.

This is my script.
First, the player clicks on a button called spin, which then puts an object value into leaderstats .
The script below is meant to identify that objectvalue and if the name is identical to the name of a tool in replicated storage that tool is then cloned into the player’s backpack.
Im new to scripting and the output doesn’t say that there is an error , so im stuck on what to do.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Elements = ReplicatedStorage:FindFirstChild("Elements")


--Fire--

-- This part of the script will give a tool to a player when they respawn. 
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Leaderstats = Player.Character.leaderstats.Inventory
		local MagicSkills = Elements.Fire:GetChildren()
			if Leaderstats.ObjectValue.Name == ("Fire") then
				MagicSkills:Clone().Parent = Player.Backpack
			end
	end)
end)
------------------------------------------------------------------------------------------------------------------------
--Earth--

-- This part of the script will give a tool to a player when they respawn. 
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Leaderstats = Player.Character.leaderstats.Inventory
		local MagicSkills = Elements.Earth:GetChildren()
			if Leaderstats.ObjectValue.Name == ("Earth") then
				MagicSkills:Clone().Parent = Player.Backpack
			end
	end)
end)

-----------------------------------------------------------------------------------------------------------------------
--Wind--

-- This part of the script will give a tool to a player when they respawn. 
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Leaderstats = Player.Character.leaderstats.Inventory
		local MagicSkills = Elements.Wind:GetChildren()
			if Leaderstats.ObjectValue.Name == ("Wind") then
				MagicSkills:Clone().Parent = Player.Backpack
			end
	end)
end)

------------------------------------------------------------------------------------------------------------------------
--Lightning--

-- This part of the script will give a tool to a player when they respawn. 
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Leaderstats = Player.Character.leaderstats.Inventory
		local MagicSkills = Elements.Lightning:GetChildren()
			if Leaderstats.ObjectValue.Name == ("Lightning") then
				MagicSkills:CLone().Parent = Player.Backpack
			end
	end)
end)
------------------------------------------------------------------------------------------------------------------------
--Water--

-- This part of the script will give a tool to a player when they respawn. 
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Leaderstats = Player.Character.leaderstats.Inventory
		local MagicSkills = Elements.Water:GetChildren()
			if Leaderstats.ObjectValue.Name == ("Water") then
				MagicSkills:Clone().Parent = Player.Backpack
			end
	end)
end)
------------------------------------------------------------------------------------------------------------------------
--Ice--

-- This part of the script will give a tool to a player when they respawn. 
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Leaderstats = Player.Character.leaderstats.Inventory
		local MagicSkills = Elements.Ice:GetChildren()
			if Leaderstats.ObjectValue.Name == ("Ice") then
				MagicSkills:Clone().Parent = Player.Backpack
			end
	end)
end)

------------------------------------------------------------------------------------------------------------------------
--Sand--

-- This part of the script will give a tool to a player when they respawn. 
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Leaderstats = Player.Character.leaderstats.Inventory
		local MagicSkills = Elements.Sand:GetChildren()
			if Leaderstats.ObjectValue.Name == ("Sand") then
				MagicSkills:Clone().Parent = Player.Backpack
		end
	end)
end)

------------------------------------------------------------------------------------------------------------------------
--Light--

-- This part of the script will give a tool to a player when they respawn. 
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Leaderstats = Player.Character.leaderstats.Inventory
		local MagicSkills = Elements.Light:GetChildren()
			if Leaderstats.ObjectValue.Name == ("Light") then
				MagicSkills:Clone().Parent = Player.Backpack
			end
	end)
end)
1 Like

You spelled :Clone() wrong. You spelt it as :CLone().

2 Likes

Oh my, I didn’t even notice. I’ll see if that is the problem, thank you for your feedback.

You’re very welcome. Can you mark it as solution if it works?

Unfortunately , that didn’t fix the problem, but it did help me fix my spelling mistake.

Is your leaderstats folder inside the player’s character? Or, can you send the leaderstats script?

Have the script print something before or after it’s suppose to clone the tools so you can test if the name check is even a true value. Let me know if it prints.

1 Like

This is the section of a script that is meant to create an objectvalue into the player’s leaderstats:

	--Check if duplicate, if not, reward item
	local duplicate = false
	if contents.DuplicateReward and leaderstats.Inventory:FindFirstChild(winningItem.Name) then
		duplicate = true
		leaderstats.Trys.Value = leaderstats.Trys.Value + itemTypes[winningItem.GroupIndex].Rarity.DuplicateReward
	else
		local newStat = Instance.new("ObjectValue")
		newStat.Name = winningItem.Name
		newStat.Parent = leaderstats.Inventory
	end

	--Returns spin details
	return {
		["Items"] = items;
		["WinningCrateId"] = winningCrateId;
		["WinningItem"] = winningItem;
		["Duplicate"] = duplicate;
	}
	
end

end


Leaderstats

and this is how it looks like after i spin and get my magic like , for example water here.

Change this line

local Leaderstats = Player.Character.leaderstats.Inventory

To this:

local Leaderstats = Player.leaderstats.Inventory
1 Like

this doesnt give players a tool when they respawn this gives them a tool when they are added to game “player.playeradded”, you can just use player.characterAdded and ALSO the efficiency in this code could be increased i think by making it all one big function

hold on imma write a local script soloution because this should really be in a local script if it isnt already

1 Like

FOR LOCAL SCRIPT
(put in starterplayer scripts or sumn)
this should work havent tested it though soooo yeah come back with any errors if there are any

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Elements = ReplicatedStorage:FindFirstChild("Elements")

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local MagicFireSkills = Elements.Fire:GetChildren()
local MagicEarthSkills = Elements.Earth:GetChildren()
local MagicWindSkills = Elements.Wind:GetChildren()
local MagicLightningSkills = Elements.Lightning:GetChildren()
local MagicWaterSkills = Elements.Water:GetChildren()

Player.CharacterAdded:Connect(function(Character)
	local Leaderstats = Player.Character.leaderstats.Inventory
	if Leaderstats.ObjectValue.Name == ("Fire") then
		MagicFireSkills:CLone().Parent = Player.Backpack
	elseif Leaderstats.ObjectValue.Name == ("Earth") then
		MagicEarthSkills:CLone().Parent = Player.Backpack
	elseif Leaderstats.ObjectValue.Name == ("Wind") then
		MagicWindSkills:CLone().Parent = Player.Backpack
	elseif Leaderstats.ObjectValue.Name == ("Lightning") then
		MagicLightningSkills:CLone().Parent = Player.Backpack
	elseif Leaderstats.ObjectValue.Name == ("Water") then
		MagicWaterSkills:CLone().Parent = Player.Backpack
	end
end)
1 Like

thank you for your reply , i’ve tried it and i got this error .

12:05:05.179 leaderstats is not a valid member of Model “Workspace.fastmubarak” - Client - MagicGiver:12

For some reason, it looked for it with the players model in workspace.

oh that’ll be because the script is looking for leaderstats in the character

on line 12 change

local Leaderstats = Player.Character.leaderstats.Inventory
to
local Leaderstats = Player.leaderstats.Inventory

cause i believe thats where u are storing the leaderstats

ok , so that fixed that problem but then i got a new problem
ObjectValue is not a valid member of Folder “Players.fastmubarak.leaderstats.Inventory” - Client - MagicGiver:13

I believe the reason is because , it trys to detect where the object value is in the inventory but you have to spin first to get that value. What should i write down on the script to tell it to wait until player , clicks claim and the value is in the inventory.

Thanks again.

Note: The spin stuff is in a different script.

alright let me see the spin script then because we’ll probably want to fire an event telling the script we just fixed when to run

Ok so this is the script for the spin button , and how the crates iterate to the right

-- << SERVICES >>
local players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local contentProvider = game:GetService("ContentProvider")
local tweenService = game:GetService("TweenService")
local runService = game:GetService("RunService") 



-- << VARIABLES >>
local player = players.LocalPlayer
local Character = player.Character
local gui = player.PlayerGui.MainFrames.Main
local spinner = gui.Spinner
local spinnerMain = spinner.Main
local spinnerReward = spinner.Reward
local claim = spinnerReward.Claim
local spin1 = spinnerReward.Spin1
local spin2 = spinnerReward.Spin2
local crates = spinnerMain.Crates
local holder = crates.Holder
local template = crates.Template
local templateX = template.AbsoluteSize.X
local crateGapX = 10
local crateTotalGapX = templateX + crateGapX
local line = spinnerMain.Line
local skip = spinnerMain.Skip
local activate = gui.ActivateSpinner
local spin = activate.Spin
local contentsModule = rs:WaitForChild("SpinnerContents")
local contents = require(contentsModule)
local itemTypes = contents:GetItemTypes()
local rfunction = contentsModule.RemoteFunction
local spinDe = true
local assetsToLoad = {}
local skipped = false
local skipTime = 0.5
local direction
local rewardSound = script.RewardSound
local Main = script.Parent.MainMenu
local Spinner = script.Parent.Spinner
local Active = script.Parent.ActivateSpinner
local Sidegui = script.Parent.Sidescreens
local PartPosition = workspace:WaitForChild("Spawn Base").MainSpawn

--Music--
local IntroMusic = game.Workspace.IntroMusic
local ClickSd = game.SoundService.Click

--Startup--
gui.Enabled = true
Sidegui.Visible = false

-- << LOCAL FUNCTIONS >>
local function DisplaySpinner(bool)
	spinner.Visible = bool
end
-- << SETUP >>
--Setup crates
template.Visible = true
for i = 1, contents.Crates do
	local pos = i-1
	local crate = template:Clone()
	crate.Name = "Crate"..i
	if string.lower(string.sub(contents.SpinDirection,1,1)) == "r" then
		direction = "Right"
		crate.Position = crate.Position + UDim2.new(0, crateTotalGapX*pos, 0, 0)
	else
		direction = "Left"
		crate.Position = crate.Position + UDim2.new(1, -(templateX+10)-(crateTotalGapX*pos), 0, 0)
	end
	crate.Parent = holder
end
template.Visible = false
--Skip button
skip.MouseButton1Down:Connect(function()
	skipped = true
end)
--Claim button
claim.MouseButton1Down:Connect(function()
	Character:WaitForChild("HumanoidRootPart").CFrame = PartPosition.CFrame
	DisplaySpinner(false)
	Main.Visible = false
	Spinner.Visible = false
	Active.Visible = false
	Sidegui.Visible = true
	IntroMusic:Stop()
	
end)
--Preload items
coroutine.wrap(function()
	for rarityPos, group in pairs(itemTypes) do
		for i, item in pairs(group.Items) do
			local decal = Instance.new("Decal")
			decal.Texture = "rbxassetid://"..item.ImageId
			table.insert(assetsToLoad, decal)
		end
	end
	contentProvider:PreloadAsync(assetsToLoad)
	for i,v in pairs(assetsToLoad) do
		if v:IsA("Decal") then
			v:Destroy()
		end
	end
end)()
--Hide display
DisplaySpinner(false)



-- << MAIN >>
function SpinFunction(spinDetails)
	
	--Variables
	local items = spinDetails.Items
	local winningCrateId = spinDetails.WinningCrateId
	local winningItem = spinDetails.WinningItem
	local duplicate = spinDetails.Duplicate
	local cratesRemaining = {}
	skipped = false
	
	--Setup crates
	holder.Position = UDim2.new(0,0,0,0)
	for i, item in pairs (items) do
		local crate = holder["Crate"..i]
		local rarityGroup = itemTypes[item.GroupIndex].Rarity
		crate.About.MagicType.Text = item.Name
		crate.About.ItemRarity.Text = rarityGroup.Name
		crate.ImageLabel.Image = "rbxassetid://"..item.ImageId
		crate.About.BackgroundColor3 = rarityGroup.Color
		if i <= winningCrateId+1 then
			table.insert(cratesRemaining, crate)
		end
	end
	
	--Calculate distance to travel
	local endCrate = holder["Crate"..winningCrateId]
	local startX = crates.AbsolutePosition.X + crates.AbsoluteSize.X/2
	local endX = endCrate.AbsolutePosition.X + endCrate.AbsoluteSize.X/2
	local xDifference = endX - startX
	local yDifference = endCrate.AbsolutePosition.Y - holder.AbsolutePosition.Y
	local templateXBound = templateX/2.5
	local randomDepth = 1000
	local landOffset = 0--math.random(-templateXBound+randomDepth, templateXBound+randomDepth)-randomDepth
	local landPosition = holder.Position - UDim2.new(0, xDifference, 0, 0) --startCrate.Position - endCrate.Position
	
	--Setup tween
	local tweenTime = math.random(contents.SpinTimeBounds[1], contents.SpinTimeBounds[2])
	local tweenInfo = TweenInfo.new(tweenTime, contents.SpinEasingStyle, contents.SpinEasingDirection)
	local tween = tweenService:Create(holder, tweenInfo, {Position = landPosition})
	
	local tweenTime = math.random(7,8)
	local tweenInfo = TweenInfo.new(tweenTime, contents.SpinEasingStyle, contents.SpinEasingDirection)
	local tween = tweenService:Create(holder, tweenInfo, {Position = landPosition})
	
	--SpinClick sounds
	local lineX = line.AbsolutePosition.X
	coroutine.wrap(function()
		repeat runService.RenderStepped:Wait()
			local cratesRemainingInt = #cratesRemaining
			local nextCrate = cratesRemaining[1]
			if nextCrate then
				local nextCrateX = nextCrate.AbsolutePosition.X
				if (direction == "Right" and nextCrateX <= lineX) or (direction == "Left" and nextCrateX >= lineX) then
					table.remove(cratesRemaining, 1)
					local sound = nextCrate.SpinClick
					sound:Play()
				end
			end
		until cratesRemainingInt <= 1 or skipped
		if skipped then
			local newTweenInfo = TweenInfo.new(skipTime, contents.SpinEasingStyle)
			local newTween = tweenService:Create(holder, newTweenInfo, {Position = landPosition})
			newTween:Play()
			newTween.Completed:Wait()
		end
		skip.Visible = false
	end)()
	
	--Show spinner
	spinnerMain.Visible = true
	spinnerReward.Visible = false
	skip.Visible = true
	DisplaySpinner(true)
	
	--Run tween
	tween:Play()
	tween.Completed:Wait()
	skip.Visible = false
	if skipped then
		wait(skipTime+0.25)
	end
	
	--Display reward
	local winningItem = items[winningCrateId]
	local rewardColor
	local rarityGroup = itemTypes[winningItem.GroupIndex].Rarity
	if duplicate then
		local h,s,v = Color3.toHSV(rarityGroup.Color)
		rewardColor = Color3.fromHSV(h, s*0.4, v*0.8)
		spinnerReward.Title.Text = contents.Messages.RewardDuplicate1(rarityGroup.Name)
		spinnerReward.MagicType.Text = contents.Messages.RewardDuplicate2(rarityGroup.DuplicateReward)
	else
		rewardColor = rarityGroup.Color
		spinnerReward.Title.Text = contents.Messages.RewardNewItem
		spinnerReward.MagicType.Text = winningItem.Name
	end
	spin1.ImageColor3 = rewardColor
	spin2.ImageColor3 = rewardColor
	spinnerReward.ItemImage.Image = "rbxassetid://"..winningItem.ImageId
	spinnerReward.Visible = true
	spinnerMain.Visible = false
	coroutine.wrap(function()
		local rotationTime = 1
		local rotationInfo = TweenInfo.new(rotationTime, Enum.EasingStyle.Linear)
		while spinnerReward.Visible do
			tweenService:Create(spin1, rotationInfo, {Rotation = spin1.Rotation + 30}):Play()
			tweenService:Create(spin2, rotationInfo, {Rotation = spin2.Rotation - 60}):Play()
			wait(rotationTime)
		end
	end)()
	rewardSound:Play()
	
end


--Select Spin
spin.MouseButton1Down:Connect(function()
	ClickSd:Play()
	if spinDe then
		spinDe = false
		local originalSpinText = spin.TextLabel.Text
		if not contents:PermissionToSpin(player) then
			spin.TextLabel.Text = contents.Messages.FailPermissionCheck
			wait(1)
		else
			spin.TextLabel.Text = contents.Messages.Loading
			local spinDetails, errorMessage = rfunction:InvokeServer()
			if not spinDetails then
				if not errorMessage then
					errorMessage = contents.Messages.ServerError
				end
				spin.TextLabel.Text = errorMessage
				wait(1)
			else
				SpinFunction(spinDetails)
			end
		end
		spin.TextLabel.Text = originalSpinText
		spinDe = true
	end
end)

can you not write raw code of this size especially as raw text

could you copy all your code just inbetween a pair of

“```” these

like this

i just find it very hard to look at all that

oh sorry about that , ill edit it now.

-- << SERVICES >>
local players = game:GetService(“Players”)
local rs = game:GetService(“ReplicatedStorage”)
local contentProvider = game:GetService(“ContentProvider”)
local tweenService = game:GetService(“TweenService”)
local runService = game:GetService(“RunService”)

-- << VARIABLES >>
local player = players.LocalPlayer
local Character = player.Character
local gui = player.PlayerGui.MainFrames.Main
local spinner = gui.Spinner
local spinnerMain = spinner.Main
local spinnerReward = spinner.Reward
local claim = spinnerReward.Claim
local spin1 = spinnerReward.Spin1
local spin2 = spinnerReward.Spin2
local crates = spinnerMain.Crates
local holder = crates.Holder
local template = crates.Template
local templateX = template.AbsoluteSize.X
local crateGapX = 10
local crateTotalGapX = templateX + crateGapX
local line = spinnerMain.Line
local skip = spinnerMain.Skip
local activate = gui.ActivateSpinner
local spin = activate.Spin
local contentsModule = rs:WaitForChild(“SpinnerContents”)
local contents = require(contentsModule)
local itemTypes = contents:GetItemTypes()
local rfunction = contentsModule.RemoteFunction
local spinDe = true
local assetsToLoad = {}
local skipped = false
local skipTime = 0.5
local direction
local rewardSound = script.RewardSound
local Main = script.Parent.MainMenu
local Spinner = script.Parent.Spinner
local Active = script.Parent.ActivateSpinner
local Sidegui = script.Parent.Sidescreens
local PartPosition = workspace:WaitForChild(“Spawn Base”).MainSpawn

–Music–
local IntroMusic = game.Workspace.IntroMusic
local ClickSd = game.SoundService.Click

–Startup–
gui.Enabled = true
Sidegui.Visible = false

– << LOCAL FUNCTIONS >>
	local function DisplaySpinner(bool)
	spinner.Visible = bool
end
– << SETUP >>
	–Setup crates
template.Visible = true
for i = 1, contents.Crates do
	local pos = i-1
	local crate = template:Clone()
	crate.Name = “Crate”…i
	if string.lower(string.sub(contents.SpinDirection,1,1)) == “r” then
		direction = “Right”
		crate.Position = crate.Position + UDim2.new(0, crateTotalGapXpos, 0, 0)
	else
		direction = “Left”
		crate.Position = crate.Position + UDim2.new(1, -(templateX+10)-(crateTotalGapXpos), 0, 0)
	end
	crate.Parent = holder
end
template.Visible = false
–Skip button
skip.MouseButton1Down:Connect(function()
	skipped = true
end)
–Claim button
claim.MouseButton1Down:Connect(function()
	Character:WaitForChild(“HumanoidRootPart”).CFrame = PartPosition.CFrame
	DisplaySpinner(false)
	Main.Visible = false
	Spinner.Visible = false
	Active.Visible = false
	Sidegui.Visible = true
	IntroMusic:Stop()

end)
–Preload items
coroutine.wrap(function()
	for rarityPos, group in pairs(itemTypes) do
		for i, item in pairs(group.Items) do
			local decal = Instance.new(“Decal”)
			decal.Texture = “rbxassetid://”…item.ImageId
			table.insert(assetsToLoad, decal)
		end
	end
	contentProvider:PreloadAsync(assetsToLoad)
	for i,v in pairs(assetsToLoad) do
		if v:IsA(“Decal”) then
			v:Destroy()
		end
	end
end)()
–Hide display
DisplaySpinner(false)

-- << MAIN >>
function SpinFunction(spinDetails)

	--Variables
	local items = spinDetails.Items
	local winningCrateId = spinDetails.WinningCrateId
	local winningItem = spinDetails.WinningItem
	local duplicate = spinDetails.Duplicate
	local cratesRemaining = {}
	skipped = false

	--Setup crates
	holder.Position = UDim2.new(0,0,0,0)
	for i, item in pairs (items) do
		local crate = holder["Crate"..i]
		local rarityGroup = itemTypes[item.GroupIndex].Rarity
		crate.About.MagicType.Text = item.Name
		crate.About.ItemRarity.Text = rarityGroup.Name
		crate.ImageLabel.Image = "rbxassetid://"..item.ImageId
		crate.About.BackgroundColor3 = rarityGroup.Color
		if i <= winningCrateId+1 then
			table.insert(cratesRemaining, crate)
		end
	end

	--Calculate distance to travel
	local endCrate = holder["Crate"..winningCrateId]
	local startX = crates.AbsolutePosition.X + crates.AbsoluteSize.X/2
	local endX = endCrate.AbsolutePosition.X + endCrate.AbsoluteSize.X/2
	local xDifference = endX - startX
	local yDifference = endCrate.AbsolutePosition.Y - holder.AbsolutePosition.Y
	local templateXBound = templateX/2.5
	local randomDepth = 1000
	local landOffset = 0--math.random(-templateXBound+randomDepth, templateXBound+randomDepth)-randomDepth
	local landPosition = holder.Position - UDim2.new(0, xDifference, 0, 0) --startCrate.Position - endCrate.Position

	--Setup tween
	local tweenTime = math.random(contents.SpinTimeBounds[1], contents.SpinTimeBounds[2])
	local tweenInfo = TweenInfo.new(tweenTime, contents.SpinEasingStyle, contents.SpinEasingDirection)
	local tween = tweenService:Create(holder, tweenInfo, {Position = landPosition})

	local tweenTime = math.random(7,8)
	local tweenInfo = TweenInfo.new(tweenTime, contents.SpinEasingStyle, contents.SpinEasingDirection)
	local tween = tweenService:Create(holder, tweenInfo, {Position = landPosition})

	--SpinClick sounds
	local lineX = line.AbsolutePosition.X
	coroutine.wrap(function()
		repeat runService.RenderStepped:Wait()
			local cratesRemainingInt = #cratesRemaining
			local nextCrate = cratesRemaining[1]
			if nextCrate then
				local nextCrateX = nextCrate.AbsolutePosition.X
				if (direction == "Right" and nextCrateX <= lineX) or (direction == "Left" and nextCrateX >= lineX) then
					table.remove(cratesRemaining, 1)
					local sound = nextCrate.SpinClick
					sound:Play()
				end
			end
		until cratesRemainingInt <= 1 or skipped
		if skipped then
			local newTweenInfo = TweenInfo.new(skipTime, contents.SpinEasingStyle)
			local newTween = tweenService:Create(holder, newTweenInfo, {Position = landPosition})
			newTween:Play()
			newTween.Completed:Wait()
		end
		skip.Visible = false
	end)()

	--Show spinner
	spinnerMain.Visible = true
	spinnerReward.Visible = false
	skip.Visible = true
	DisplaySpinner(true)

	--Run tween
	tween:Play()
	tween.Completed:Wait()
	skip.Visible = false
	if skipped then
		wait(skipTime+0.25)
	end

	--Display reward
	local winningItem = items[winningCrateId]
	local rewardColor
	local rarityGroup = itemTypes[winningItem.GroupIndex].Rarity
	if duplicate then
		local h,s,v = Color3.toHSV(rarityGroup.Color)
		rewardColor = Color3.fromHSV(h, s*0.4, v*0.8)
		spinnerReward.Title.Text = contents.Messages.RewardDuplicate1(rarityGroup.Name)
		spinnerReward.MagicType.Text = contents.Messages.RewardDuplicate2(rarityGroup.DuplicateReward)
	else
		rewardColor = rarityGroup.Color
		spinnerReward.Title.Text = contents.Messages.RewardNewItem
		spinnerReward.MagicType.Text = winningItem.Name
	end
	spin1.ImageColor3 = rewardColor
	spin2.ImageColor3 = rewardColor
	spinnerReward.ItemImage.Image = "rbxassetid://"..winningItem.ImageId
	spinnerReward.Visible = true
	spinnerMain.Visible = false
	coroutine.wrap(function()
		local rotationTime = 1
		local rotationInfo = TweenInfo.new(rotationTime, Enum.EasingStyle.Linear)
		while spinnerReward.Visible do
			tweenService:Create(spin1, rotationInfo, {Rotation = spin1.Rotation + 30}):Play()
			tweenService:Create(spin2, rotationInfo, {Rotation = spin2.Rotation - 60}):Play()
			wait(rotationTime)
		end
	end)()
	rewardSound:Play()
end

–Select Spin
spin.MouseButton1Down:Connect(function()
	ClickSd:Play()
	if spinDe then
		spinDe = false
		local originalSpinText = spin.TextLabel.Text
		if not contents:PermissionToSpin(player) then
			spin.TextLabel.Text = contents.Messages.FailPermissionCheck
			wait(1)
		else
			spin.TextLabel.Text = contents.Messages.Loading
			local spinDetails, errorMessage = rfunction:InvokeServer()
			if not spinDetails then
				if not errorMessage then
					errorMessage = contents.Messages.ServerError
				end
				spin.TextLabel.Text = errorMessage
				wait(1)
			else
				SpinFunction(spinDetails)
			end
		end
		spin.TextLabel.Text = originalSpinText
		spinDe = true
	end
end)

format your code with three backticks above the first line and then three more below the last line of your script

1 Like

Thank you for the info, I’ll make sure to do that in the future

1 Like