[Request for Scripting Help] Need help /w Fixing Roll button with roll animation to make an Sol’s RNG-like roblox game

Hello there, over the three days of Development with the ChatGPT’s scripting support, I have kinda constructed the Aura equip system, aura inventory system, aura unequip system, Spend IntValue to roll an Aura, total rolls value and such for my Sol’s Rng like game, but today, I have ran into the Problem where Roll button will not work and wouldn’t Invoke the RollEvent RemoteFunction when clicked, it has became pretty complicated through to much attempts of generating an Script with ChatGPT, but I will show you the Roblox place file and chatGPT conversation share Link to here…

  1. so I want to build an system where the Script will first show an rolls of three fake rolls that player wouldn’t get, and the three fake rolls and one real roll will be shown through an Rolling Animation, it is kind of complicated Process so I believe you would have to watch This youtube video where I took an Rolling animation from and Download my rbxl File to see what is actually wrong and what I have been trying to do…

  2. either ServerScriptService Script, or LocalScript inside StarterGui, or ModuleScript inside StarterGui is having an trouble that it wouldn’t invoke an RollEvent when the Roll button is pressed… :slightly_frowning_face:

  3. I have used ChatGPT’s AI Scripting Support, yes, I know that sucks so bad but there wasn’t really any options for me at that time until I have started to ask you guys about this issues… ;-;

so I will just Share an ServerScriptService Script, LocalScript, ModuleScript inside LocalScript into lua code box format, and also show you the rbxl file of my test game including basically all of sufficient items or scripts in there, so if you do want to help me out, it would be advised to download the rbxl files and open it, and thank you so much for your generous efforts if you do download the rbxl file and open it for analyze it :face_holding_back_tears:

-- ServerScriptService Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local CombinedDataStore = DataStoreService:GetDataStore("CombinedDataStore")
local Players = game:GetService("Players")
local RollEvent = ReplicatedStorage:WaitForChild("RollEvent")
local AuraHandler = require(script.Parent:WaitForChild("AuraHandler"))

local Inventory = {}
local Rolls = {}
local RollaBoon = {}

local WastedLatestRoll = {}
local CanWaste = {}
local EquippedAura = {}

local auras = {
	["Common"] = { Chances = 2, Color = Color3.fromRGB(224, 248, 255) },
	["Bleeding"] = { Chances = 4444, Color = Color3.fromRGB(159, 75, 76) },
	["Uncommon"] = { Chances = 4, Color = Color3.fromRGB(219, 255, 217) },
	["Goog"] = { Chances = 6, Color = Color3.fromRGB(255, 244, 202) },
	["Natural"] = { Chances = 10, Color = Color3.fromRGB(245, 255, 194) },
	["Nice"] = { Chances = 13, Color = Color3.fromRGB(247, 255, 156) },
	["Rare"] = { Chances = 16, Color = Color3.fromRGB(187, 218, 255) },
	["Better"] = { Chances = 22, Color = Color3.fromRGB(255, 224, 185) },
	["Noticeable"] = { Chances = 27, Color = Color3.fromRGB(255, 160, 143) },
	["Nice : Believing"] = { Chances = 30, Color = Color3.fromRGB(244, 255, 169) },
	["Divinus"] = { Chances = 35, Color = Color3.fromRGB(255, 255, 131) },
	["Divinus : Love"] = { Chances = 47, Color = Color3.fromRGB(255, 200, 230) },
	["Great"] = { Chances = 58, Color = Color3.fromRGB(0, 0, 0) }, --incomplete Aura
	["Unique"] = { Chances = 92, Color = Color3.fromRGB(0, 0, 0) }, --incomplete Aura
	["Gilded"] = { Chances = 512, Color = Color3.fromRGB(0, 0, 0) }, --incomplete Aura
	["Special"] = { Chances = 651, Color = Color3.fromRGB(0, 0, 0) }, --incomplete Aura
	["Jackpot"] = { Chances = 777, Color = Color3.fromRGB(0, 0, 0) }, --incomplete Aura
	["Diaboli"] = { Chances = 1004, Color = Color3.fromRGB(0, 0, 0) }, --incomplete Aura
	["CapyBapy"] = { Chances = 117707, Color = Color3.fromRGB(170, 107, 60) },
	["Archangel"] = { Chances = 2.5e8, Color = Color3.fromRGB(0, 0, 0) }, --incomplete Aura
	["Impeached"] = { Chances = 2e8, Color = Color3.fromRGB(0, 0, 0) }, --incomplete Aura
}

local luckBoost = 1

local RollingAnimationDuration = 1.5

local function roll(User, luckBoost)
	local accumulatedWeight = 0
	local totalWeight = 0
	local prizeName, prizeColor

	for _, aura in pairs(auras) do
		totalWeight = totalWeight + aura.Chances ^ -1 / (luckBoost or 1)
	end

	local rollValue = math.random() * totalWeight

	for auraName, aura in pairs(auras) do
		accumulatedWeight = accumulatedWeight + aura.Chances ^ -1 / (luckBoost or 1)
		if accumulatedWeight >= rollValue then
			prizeName = auraName
			prizeColor = aura.Color
			break
		end
	end

	return prizeName, prizeColor
end

local function SavePlayerData(User)
	local userId = User.UserId
	local success, err = pcall(function()
		local saveData = {
			Inventory = Inventory[userId],
			Rolls = Rolls[userId],
			RollaBoon = RollaBoon[userId]  -- Save RollaBoon value
		}
		CombinedDataStore:SetAsync("PlayerData"..userId, saveData)
		-- Save equipped aura
		if Inventory[userId] and Inventory[userId]["Equipped"] then
			CombinedDataStore:SetAsync("EquippedAura"..userId, Inventory[userId]["Equipped"])
		end
	end)
	if not success then
		warn("Failed to save data for player "..userId..": "..err)
	end
end

local function LoadPlayerData(User)
	local userId = User.UserId
	local success, data = pcall(function()
		return CombinedDataStore:GetAsync("PlayerData"..userId)
	end)
	if success then
		Inventory[userId] = data and data.Inventory or {
			Limit = 42, 
			LatestRoll = nil,
			Equipped = nil,
			Backpack = {},
			RollaBoon = 0  -- Set default value for RollaBoon
		}
		Rolls[userId] = data and data.Rolls or 0
		EquippedAura[userId] = CombinedDataStore:GetAsync("EquippedAura"..userId) or nil
		RollaBoon[userId] = data and data.RollaBoon or 0  -- Load RollaBoon value
	else
		warn("Failed to load data for player "..userId)
	end
	-- Load equipped aura from data and equip it
	if EquippedAura[userId] then
		Inventory[userId]["Equipped"] = EquippedAura[userId]
		AuraHandler.EquipAura(User, User.Character, EquippedAura[userId])
	end
end

Players.PlayerAdded:Connect(function(Player)
	LoadPlayerData(Player)

	local Data = Instance.new("Folder", Player)
	Data.Name = "leaderstats"

	local RollsValue = Instance.new("IntValue", Data)
	RollsValue.Name = "Rolls"
	if Rolls[Player.UserId] then
		RollsValue.Value = Rolls[Player.UserId]
	end

	local RollaBoonValue = Instance.new("IntValue", Data)
	RollaBoonValue.Name = "RollaBoon"
	RollaBoonValue.Value = RollaBoon[Player.UserId]

	Player:WaitForChild("leaderstats"):WaitForChild("RollaBoon").Changed:Connect(function(newValue)
		RollaBoon[Player.UserId] = newValue
		SavePlayerData(Player)
	end)
end)

local function AutoSaveData()
	while true do
		for _, player in ipairs(Players:GetPlayers()) do
			SavePlayerData(player)
			print("Player Data has been Saved :)")
		end
		wait(22) 
	end
end

coroutine.wrap(AutoSaveData)()

local function DeleteAuraFromInventory(User, AuraToDelete)
	if AuraToDelete then
		local Backpack = Inventory[User.UserId]["Backpack"]
		for i = #Backpack, 1, -1 do
			if Backpack[i] == AuraToDelete then
				table.remove(Backpack, i)
				print("Aura " .. AuraToDelete .. " has been deleted from inventory")
				break
			end
		end
	end
end

RollEvent.OnServerInvoke = function(User, Header, AuraToDelete)
	local UserInventory = Inventory[User.UserId]
	if not UserInventory then
		return
	end
	local UserLimit = UserInventory["Limit"]
	local Backpack = UserInventory["Backpack"]

	if Header == "Roll" then
		local isFakeRoll = false
		if luckBoost > 1 then
			isFakeRoll = true
		end

		if isFakeRoll then
			-- Perform fake rolls
			local fakeRolls = {}
			for _ = 1, 3 do
				local fakePrizeName, fakePrizeRarity, fakePrizeColor = roll(User, luckBoost)
				table.insert(fakeRolls, { Name = fakePrizeName, Rarity = fakePrizeRarity, Color = fakePrizeColor })
			end
			-- Pass fake roll data to the client in the correct format
			RollEvent:InvokeClient(User, "Roll", fakeRolls)
		else
			-- Perform the actual roll
			local prizeName, prizeRarity, prizeColor = roll(User, luckBoost)
			if #Backpack >= UserLimit then
				table.remove(Backpack, 1)
			end
			table.insert(Backpack, prizeName)
			UserInventory["LatestRoll"] = prizeName
			Rolls[User.UserId] = (Rolls[User.UserId] or 0) + 1
			WastedLatestRoll[User.UserId] = false
			-- Pass the actual roll result to the client in the correct format
			RollEvent:InvokeClient(User, "Roll", { Name = prizeName, Rarity = prizeRarity, Color = prizeColor })
			-- Return roll details
			return prizeName, prizeRarity, prizeColor
		end
	elseif Header == "Delete" then
		DeleteAuraFromInventory(User, AuraToDelete)
	elseif Header == "Get" then
		return UserInventory["LatestRoll"]
	elseif Header == "Waste" then
		if not CanWaste[User.UserId] then
			CanWaste[User.UserId] = true
			if not WastedLatestRoll[User.UserId] then
				for i, itemName in ipairs(Backpack) do
					if itemName == UserInventory["LatestRoll"] then
						table.remove(Backpack, i)
						break
					end
				end
				UserInventory["LatestRoll"] = nil
				WastedLatestRoll[User.UserId] = true
			end
			wait(1)
			CanWaste[User.UserId] = false
		end
	elseif Header == "GetInventory" then
		return Backpack
	else
		return "Invalid header"
	end
	-- Save player data outside the if-elseif block
	SavePlayerData(User)
end


Players.PlayerAdded:Connect(function(Player)
	Player:WaitForChild("leaderstats"):WaitForChild("RollaBoon").Changed:Connect(function(newValue)
		RollaBoon[Player.UserId] = newValue
		SavePlayerData(Player)
	end)
end)

--LocalScript inside StarterGui

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RollEvent = ReplicatedStorage:WaitForChild("RollEvent")

local AuraSelectValue = game.Players.LocalPlayer.Character:WaitForChild("AuraSelectedValue")

local Get = script.Parent.Parent.Parent:WaitForChild("Get")
local Waste = script.Parent.Parent.Parent:WaitForChild("Waste")
local animationfolder = game.Players.LocalPlayer.PlayerGui:WaitForChild("RollButtonGui"):WaitForChild("Animations")
local result = animationfolder:WaitForChild("Result")
local Background = animationfolder:WaitForChild("BackGround")
local Roll = script.Parent
local InventoryView = script.Parent.Parent.Parent:WaitForChild("Inventory", true)
local InventoryGUI = script.Parent.Parent.Parent:WaitForChild("InventoryGUI", true)
local InventoryList = InventoryGUI:WaitForChild("InventoryList")
local SelectAuraTextframe = InventoryGUI:WaitForChild("SelectedAuraTextFrame")

local AnimationModule = require(script:WaitForChild("AnimationModule"))

local User = game.Players.LocalPlayer

local function DisplayResult(Show)
	Get.Visible, Waste.Visible, Roll.Visible = Show, Show, not Show
end

local IsViewing = false
InventoryView.MouseButton1Click:Connect(function()
	IsViewing = not IsViewing
	InventoryGUI.Visible = IsViewing

	if not IsViewing then
		for _, Value in pairs(InventoryList:GetChildren()) do
			Value:Remove()
		end
	else
		local ClientInventory = RollEvent:InvokeServer("GetInventory")
		print(ClientInventory)
		for Index, Value in pairs(ClientInventory) do
			local Item = Instance.new("TextButton")
			Item.Parent = InventoryList
			Item.TextScaled = true
			Item.Visible = true
			Item.Text = Value
			Item.Name = "Item_" .. Index
			Item.Position = UDim2.fromScale((Index - 1) % 5 * 0.2, math.floor((Index - 1) / 5) * 0.1)
			Item.Size = UDim2.fromScale(0.2, 0.1)
			Item.MouseButton1Click:Connect(function()
				AuraSelectValue.Value = Value
				SelectAuraTextframe.Text = Value
			end)
		end
	end
end)

Get.MouseButton1Click:Connect(function()
	RollEvent:InvokeServer("Get")
	DisplayResult(false)
	result.Visible = false
	Background.Visible = false
end)

Waste.MouseButton1Click:Connect(function()
	RollEvent:InvokeServer("Waste")
	DisplayResult(false)
	result.Visible = false
	Background.Visible = false
end)

local RollaBoonValue = User:WaitForChild("leaderstats"):FindFirstChild("RollaBoon")

Roll.MouseButton1Click:Connect(function()
	print("The Roll button has been clicked, will it roll?")
	if RollaBoonValue and RollaBoonValue.Value >= 1 then
		local success, prizeName, prizeRarity, prizeTextColor = pcall(function()
			return RollEvent:InvokeServer("Roll")
		end)
		if success then
			AnimationModule.rollAnimation(animationfolder, prizeName, prizeRarity, prizeTextColor, User)
			wait(2.1)
			DisplayResult(true)
			if RollaBoonValue then
				RollaBoonValue.Value = RollaBoonValue.Value - 1
			end
		else
			print("Error occurred while rolling:", prizeName)
		end
	end
end)

ModuleScript inside LocalScript 

local TweenService = game:GetService("TweenService")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RollEvent = ReplicatedStorage:WaitForChild("RollEvent")

local info = TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)

local function animatedText(title, rarityLabel, prizeRarity, prizeTextColor)
	title.Position = UDim2.fromScale(0.5, 0.35)
	title.TextColor3 = prizeTextColor
	title.Visible = true
	if prizeRarity then
		rarityLabel.Text = '1 in ' .. prizeRarity .. ' chance'
	else
		rarityLabel.Text = '1 in unknown chance'
	end

	TweenService:Create(title, info, {Position = UDim2.fromScale(0.5, 0.5)}):Play()
	wait(0.2)
end

local function animateRoll(animationfolder, prizeData)
	-- Check if animationfolder is a string, if so, convert it to an actual object reference
	if typeof(animationfolder) == "Instance" then
		animationfolder = game:GetService("Players").LocalPlayer.PlayerGui[animationfolder]
	end

	local background = animationfolder:WaitForChild("BackGround") -- Ensure animationfolder is an object reference
	local title = animationfolder:WaitForChild("Result")
	local rarityLabel = title:WaitForChild("Rarity") -- Store a reference to the Rarity TextLabel

	background.Visible = true
	title.Visible = true

	-- Display roll data
	title.Text = prizeData.Name or "No result"
	title.TextColor3 = prizeData.Color or Color3.new(1, 1, 1) -- Set a default value if prizeData.Color is nil
	wait(0.1)
	animatedText(title, rarityLabel, prizeData.Rarity, prizeData.Color) -- Pass prizeData.Rarity and prizeData.Color separately
end

return {
	rollAnimation = function(animationfolder, prizeData, User)
		if type(prizeData) == "table" then
			-- Display fake or real rolls
			animateRoll(animationfolder, prizeData)

			-- If prizeData represents a fake roll, don't invoke RollEvent
			if prizeData.Color then
				return
			end

			-- Perform the actual roll
			RollEvent:InvokeClient(User, "Roll", prizeData.Name, prizeData.Rarity, prizeData.Color)
		else
			warn("Invalid prize data format")
		end
	end
}

thank you for reading all of my Topic posts, and in a hopes of fixing the Error with my roblox game / experience, I will also post the rbxl file into here, so feel free to check out my Test game, and also you may take my Roblox Scripts inside rbxl files for transformative purposes :hugs:

SolsRNGLikeGameTest3 - RollButtonNotWorkingError.rbxl (419.6 KB)

thank you for either Noticing or helping me in this Topic! -mari