Backstory: I’m trying to make a currency system that checks if you enough funds to select the betting option
Can you send us the script so we can see whats wrong?
--// Betting Section
local bet = 0
local Error = script.Parent.Parent.ErrorText
local CurrentText = script.Parent.Parent.CurrentBet
if game.Players.LocalPlayer.leaderstats.Cash == nil then
repeat
until game.Players.LocalPlayer.leaderstats.Cash ~= nil
end
local A = script.Parent.Parent.bet10
function B1()
if game.Players.LocalPlayer.leaderstats.Cash >= 10 then
bet = 10
print('Current Bet: '..bet)
CurrentText.Text = ('Current Bet: '..bet)
else
Error.Visible = true
wait(3)
Error.Visible = false
end
end
A.MouseButton1Click:Connect(B1)
local B = script.Parent.Parent.bet25
function B2()
if game.Players.LocalPlayer.leaderstats.Cash >= 25 then
bet = 25
print('Current Bet: '..bet)
CurrentText.Text = ('Current Bet: '..bet)
else
Error.Visible = true
wait(3)
Error.Visible = false
end
end
B.MouseButton1Click:Connect(B2)
local C = script.Parent.Parent.bet50
function B3()
if game.Players.LocalPlayer.leaderstats.Cash >= 50 then
bet = 50
print('Current Bet: '..bet)
CurrentText.Text = ('Current Bet: '..bet)
else
Error.Visible = true
wait(3)
Error.Visible = false
end
end
C.MouseButton1Click:Connect(B3)
local D = script.Parent.Parent.bet75
function B4()
if game.Players.LocalPlayer.leaderstats.Cash >= 75 then
bet = 75
print('Current Bet: '..bet)
CurrentText.Text = ('Current Bet: '..bet)
Error.Visible = true
wait(3)
Error.Visible = false
end
end
D.MouseButton1Click:Connect(B4)
local E = script.Parent.Parent.bet100
function B5()
if game.Players.LocalPlayer.leaderstats.Cash >= 100 then
bet = 100
print('Current Bet: '..bet)
CurrentText.Text = ('Current Bet: '..bet)
Error.Visible = true
wait(3)
Error.Visible = false
end
end
E.MouseButton1Click:Connect(B5)
--// Spawn Ball Section
function leftClick()
local SS = game:GetService("ServerStorage")
local BallList = SS:WaitForChild("PlinkoBalls")
local Balls = BallList:GetChildren()
local items = BallList:GetChildren()
local randomBall = items[math.random(1, #items)]
print("Plink Ball")
local ballCopy = randomBall:Clone()
for i = 1, #Balls do
ballCopy.Parent = game.Workspace.Plinko.Balls
ballCopy.Name = "PlinkoBall"
ballCopy.Value.Value = bet
end
end
script.Parent.MouseButton1Click:Connect(leftClick)
The idea behind it is that if you don’t have equal to or the bet amount then it will say
“insufficient funds” that way people can’t bet money they don’t have
Only issue is that it doesn’t allow me to get the path for leaderboard so the script errors
Is this a script or a local script?
This is inside a normal script not local
Then, game.Players.LocalPlayer will return nil if the script is a normal script.
So what should I do, change it to a local script?
Move this code over to a local script and make use of RemoteEvents in order to pass the data to the server.
change leaderstats.Cash
to leaderstats.Cash.Value
Ah yes thank you for catching my mistake I appreciate that, what were you saying about remote events?
Remote Events are used to send data from the client (player) to the server. Anything client sided can only be viewed by the client whereas changed made on the server are global.
--// Spawn Ball Section
function SpawnBall()
local SS = game:GetService("ServerStorage")
local BallList = SS:WaitForChild("PlinkoBalls")
local Balls = BallList:GetChildren()
local items = BallList:GetChildren()
local randomBall = items[math.random(1, #items)]
print("Plink Ball Purchased")
local ballCopy = randomBall:Clone()
for i = 1, #Balls do
ballCopy.Parent = game.Workspace.Plinko.Balls
ballCopy.Name = "PlinkoBall"
ballCopy.Value.Value = bet
end
end
script.Parent.MouseButton1Click:Connect(SpawnBall)
I’ve seemed to run into a new issue it doesn’t let me spawn balls
ServerStorage cannot be accessed from the client.
So a local script won’t be able to get the ServerStorage? What if I changed the location to replicated storage?
That should work perfectly without any issues.
It’s like every fix makes a new issue, now the detectors won’t work when the ball hits
script.Parent.Touched:Connect(function(h)
if h:IsA("Part") and h.Name == "PlinkoBall" then
print('1.0x Triggered')
wait(0.2)
local outcome = h.Value.Value * 1.0
print(outcome)
h:Destroy()
end
end)
Any ideas on what can be causing it to mess up? ^
is that a client sided script or a server sided script?