EDIT 2 I found it, when using DataStore2, you must use the dot operator when using Combine like this:
DataStore2.Combine("MasterKey", "Store1", ... ,"StoreN")
But I had been using the colon operator like this:
DataStore2:Combine("MasterKey", "Store1", ... ,"StoreN")
EDIT: Upon further examination, I believe the issue is with the DataStore2 module I'm using, not these scripts themselves. When I test the game on a local server, upon the second player joining I get the following output:
15:26:49.988 - ServerScriptService.DataStore2:479: DataStore2() API call expected {string dataStoreName, Instance player}, got {table, Instance}
15:26:50.001 - Stack Begin
15:26:50.004 - Script 'ServerScriptService.DataStore2', Line 479 - function __call
15:26:50.007 - Script 'ServerScriptService.DataStore2', Line 491 - function __call
15:26:50.008 - Script 'ServerScriptService.MainDataStore', Line 8
15:26:50.009 - Stack End
Not quite sure what this means but I'm going to keep looking.
OG POST
I'm having trouble figuring out what is wrong with these scripts, because I have other GUI's which function perfectly regardless of how many players are in game. This is the only one which is giving me trouble and I can't figure it out.
So there is a button when pressed should award the player a random amount of cash from 1 to 6. It works with one player in-game but as soon as another joins, it completely breaks.
This is the local script which is inside a button:
local rollEvent = game:GetService("ReplicatedStorage"):WaitForChild("rollEvent") --remote event to fire to server script
local CooldownBar = script.Parent.Parent.CooldownBar --this is to show the remaining time before button can be clicked again
local CooldownText = CooldownBar.TimeRemaining --this too
local bar = CooldownBar.ActualBar --this too
local debounce = false --debounce for the cooldown
local player = game.Players.LocalPlayer --gets player to send to server script
script.Parent.MouseButton1Click:Connect(function()
if debounce then --debounce true then dont do anything
return
end
debounce = true --else set it to true and continue
rollEvent:FireServer(player) --fire to server script
local rollCooldown = game.Players.LocalPlayer.vars.rollCooldown --gets the cooldown value from player data
bar.Size = UDim2.new(0, 0, .8, 0) --controls cooldown bar size to show when you can click button again
bar:TweenSize(UDim2.new(.975, 0, .8, 0), "Out", "Linear", rollCooldown.Value, true)
local secondsToRun = rollCooldown.Value
local endTime = tick() + secondsToRun -- float representing when the timer was started
while tick() < endTime do -- run until 'secondsToRun' seconds have passed
game:GetService("RunService").Heartbeat:Wait() -- this waits until the heartbeat event is triggered, which happens 60 times a second
local timeSinceStart = endTime - tick()
local numberText = string.format("%0.1f", tostring(timeSinceStart)) -- 0.1 represents one decimal
CooldownText.Text = numberText
end
CooldownText.Text = "Ready!"
debounce = false --button can now be clicked again
end)
And this is the server sided script in server script service:
local rollEvent = game:GetService("ReplicatedStorage"):WaitForChild("rollEvent")
local debounce = false
rollEvent.OnServerEvent:Connect(function(player) --when event is fired, do the function
if debounce then --just to prevent exploits
return
end
debounce = true
local vars = player:WaitForChild("vars")
local cash = vars:WaitForChild("Cash")
local rollCooldown = vars:WaitForChild("rollCooldown")
local lastRoll = player:WaitForChild("lastRoll")
local chance = math.random(1,6)
local cashDataStore = dataStore2("Cash", player) --get cash datastore
cashDataStore:Increment(chance) --update the value
lastRoll.Value = chance --sent back to client to show how much the last click gave them
rollEvent:FireClient(player, lastRoll)
wait(rollCooldown.Value - 0.05)
debounce = false
end)
I honestly cannot figure it out but knowing me, it's probably something really dumb or minor that I just can't find. If you need any more information or scripts I can provide it.
