Hello i want to make a roblox game like Steal a brainrot but instead of brainrots there will be balls now i have these two scripts which arent wanna function that well so: return {
["NormalBall"] = { rarity = 60, price = 10 },
["PingPongBall"] = { rarity = 20, price = 20 },
["TennisBall"] = { rarity = 10, price = 30 },
["BeachBall"] = { rarity = 5, price = 50 },
["B-Ball"] = { rarity = 3, price = 75 },
["FootballBall"] = { rarity = 1.5, price = 90 },
["Floppaballsd"] = { rarity = 0.5, price = 100 }
}
and the other one: -- File: ServerScriptService/BallSystemHandler
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local Workspace = game:GetService("Workspace")
local BallData = require(ReplicatedStorage:WaitForChild("BallRarities"))
local BallModels = Workspace:WaitForChild("BallModels")
local Waypoint1 = Workspace.Path:WaitForChild("Waypoint1")
local Waypoint2 = Workspace.Path:WaitForChild("Waypoint2")
local FLOAT_HEIGHT = 2
local TWEEN_DURATION = 40
local SPAWN_DELAY = 4
-- Remote Setup
local Remotes = ReplicatedStorage:FindFirstChild("Remotes") or Instance.new("Folder")
Remotes.Name = "Remotes"
Remotes.Parent = ReplicatedStorage
local BuyBall = Remotes:FindFirstChild("BuyBall") or Instance.new("RemoteEvent")
BuyBall.Name = "BuyBall"
BuyBall.Parent = Remotes
-- Prep ball
local function prepareBall(ball)
if ball:IsA("Model") then
for _, part in ipairs(ball:GetDescendants()) do
if part:IsA("BasePart") then
part.CanCollide = false
part.Anchored = true
end
end
elseif ball:IsA("BasePart") then
ball.CanCollide = false
ball.Anchored = true
end
end
local function moveBall(ball)
local mover = ball:IsA("Model") and ball.PrimaryPart or ball
if not mover then return end
local targetPos = Waypoint2.Position + Vector3.new(0, FLOAT_HEIGHT, 0)
TweenService:Create(mover, TweenInfo.new(TWEEN_DURATION, Enum.EasingStyle.Linear), { Position = targetPos }):Play()
task.delay(TWEEN_DURATION, function()
if ball and ball.Parent then
ball:Destroy()
end
end)
end
-- Ball spawn loop
task.spawn(function()
while true do
local totalWeight = 0
local chosenName = nil
for _, info in pairs(BallData) do totalWeight += info.rarity end
local rand = math.random() * totalWeight
local acc = 0
for name, info in pairs(BallData) do
acc += info.rarity
if rand <= acc then chosenName = name break end
end
if chosenName then
local template = BallModels:FindFirstChild(chosenName)
if template then
local clone = template:Clone()
local pos = Waypoint1.Position + Vector3.new(0, FLOAT_HEIGHT, 0)
if clone:IsA("Model") and clone.PrimaryPart then
clone:SetPrimaryPartCFrame(CFrame.new(pos))
elseif clone:IsA("BasePart") then
clone.CFrame = CFrame.new(pos)
end
clone.Parent = Workspace
prepareBall(clone)
moveBall(clone)
end
end
task.wait(SPAWN_DELAY)
end
end)
-- Handle ball buy
BuyBall.OnServerEvent:Connect(function(player, ballName)
local info = BallData[ballName]
if not info then return end
local money = player:FindFirstChild("Money")
if not money or money.Value < info.price then
BuyBall:FireClient(player, false, ballName)
return
end
money.Value -= info.price
BuyBall:FireClient(player, true, ballName)
-- Find base
local base
for i = 1, 8 do
local b = Workspace:FindFirstChild("Base" .. i)
if b and b:GetAttribute("Owner") == player.UserId then base = b break end
end
if not base then return end
local follow = base:FindFirstChild("BallFollowPart")
local locations = {}
for i = 1, 8 do
local loc = base:FindFirstChild("BallLocation" .. i)
if loc then table.insert(locations, loc) end
end
local ball = BallModels:FindFirstChild(ballName):Clone()
ball.Parent = Workspace
prepareBall(ball)
local mover = ball:IsA("Model") and ball.PrimaryPart or ball
if follow and mover then
TweenService:Create(mover, TweenInfo.new(1), {CFrame = follow.CFrame + Vector3.new(0,2,0)}):Play()
task.wait(1.1)
for _, loc in ipairs(locations) do
if #loc:GetChildren() == 0 then
TweenService:Create(mover, TweenInfo.new(1), {CFrame = loc.CFrame + Vector3.new(0,2,0)}):Play()
task.wait(1.1)
ball.Parent = loc
break
end
end
end
end)
-- Assign base
Players.PlayerAdded:Connect(function(player)
local money = Instance.new("IntValue")
money.Name = "Money"
money.Value = 100
money.Parent = player
local spawnCFrame = nil
for i = 1, 8 do
local base = Workspace:FindFirstChild("Base" .. i)
if base and not base:GetAttribute("Owner") then
base:SetAttribute("Owner", player.UserId)
-- SurfaceGui sign fix
local sign = base:FindFirstChild("Sign", true)
if sign then
local gui = sign:FindFirstChildWhichIsA("SurfaceGui")
if gui then
local label = gui:FindFirstChild("NameLabel")
if label then label.Text = player.Name .. "'s Base" end
end
end
-- Save spawn CFrame
local spawn = base:FindFirstChild("SpawnPoint")
if spawn then
spawnCFrame = spawn.CFrame
end
break
end
end
if spawnCFrame then
player.CharacterAdded:Connect(function(char)
char:WaitForChild("HumanoidRootPart").CFrame = spawnCFrame
end)
end
end)
and so like the buying doesnt wanna work like here are the last two scripts also: local BuyEvent = game.ReplicatedStorage.Remotes.BuyBall
local gui = script.Parent
local successText = gui:WaitForChild("Successfull")
local failText = gui:WaitForChild("UnSuccessfull")
BuyEvent.OnClientEvent:Connect(function(success, ballName)
if success then
successText.Text = "Successfully Bought " .. ballName
successText.Visible = true
task.wait(2)
successText.Visible = false
else
failText.Text = "Failed To Buy " .. ballName
failText.Visible = true
task.wait(2)
failText.Visible = false
end
end)
local player = game.Players.LocalPlayer
local label = script.Parent.TextLabel
local money = player:WaitForChild("Money")
money:GetPropertyChangedSignal("Value"):Connect(function()
label.Text = "Money: "..money.Valueend)label.Text="Money"..money.Value
just fix it...