[HELP] Simulator Scripts not Working Correctly

Backstory

So I made a simulator, tested everything in studio and it was working fine. I release it, and the clicking part broke. I am pretty sure it has to do with the data store. I know this because the data store was saving the level value as 0 when it should be 1. This causes the clicking to do nothing because it multiplies 10 by the level.

How I tried to solve it.

At first I changed the data store key. It didn’t do anything except make it worse. Every time I clicked it gave me an insane amount. But for others they couldn’t click at all. So I don’t know if I am doing the data store wrong or if it is something else.

Data Store Script

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("dsaferw")

game.Players.PlayerAdded:Connect(function(player)
	
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local Claps = Instance.new("IntValue")
Claps.Name = "Claps"
Claps.Parent = leaderstats

local totalClaps = Instance.new("IntValue")
totalClaps.Name = "totalClaps"
totalClaps.Parent = player

local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = leaderstats

local Plus = Instance.new("NumberValue")
Plus.Name = "Plus"
Plus.Parent = player
Plus.Value = 1

local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = leaderstats

local KeyLevel = Instance.new("IntValue")
KeyLevel.Name = "KeyLevel"
KeyLevel.Parent = player


local playerUserId = "Player_"..player.UserId

	
local data
local success, errormessage = pcall(function()
	data = myDataStore:GetAsync(playerUserId)
end)
	
if success and data then
	Claps.Value = data[1]
	Level.Value = data[2]
	Plus.Value = data[3]
	Money.Value = data[4]
	totalClaps.Value = data[5]
	KeyLevel.Value = data[7]
else
	print("Data not found")
end
end)

game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId

local data = {
	player.leaderstats.Claps.Value;
	player.leaderstats.Level.Value;
	player.leaderstats.Money.Value;
	player.Plus.Value;
	player.totalClaps.Value;
	player.KeyLevel.Value
}



local success, errormessage = pcall(function()
	myDataStore:SetAsync(playerUserId, data)
end)
	
if success then
	print("Data saved")	
else
	print("Error in saving data")
	warn(errormessage)
end
end)

Clicking Scripts

local player = game.Players.LocalPlayer
local animation = script.Animation
local char = workspace:FindFirstChild(player.Name)
local humanoid = char:WaitForChild("Humanoid")
local animationTrack = humanoid:LoadAnimation(animation)
local debounce = false

local function clap()
	animationTrack:Play()
	script.Clap:Play()
	wait(1.16)
	game:GetService("ReplicatedStorage").GiveCoins:FireServer(player)
	animationTrack:Stop()
	script.Clap:Stop()
end


script.Parent.MouseButton1Click:Connect(function()
	if not debounce then
		debounce = true
		clap()
		wait()
		debounce = false
	end
end)

script.Parent.MouseEnter:Connect(function()
	script.Parent.TextButton_Roundify_2px.ImageColor3 = Color3.fromRGB(0, 95, 143)
end)

script.Parent.MouseLeave:Connect(function()
	script.Parent.TextButton_Roundify_2px.ImageColor3 = Color3.fromRGB(00, 170, 255)
end)

script.Parent.TouchTap:Connect(function()
	if not debounce then
		debounce = true
		clap()
		wait()
		debounce = false
	end
end)
game:GetService("ReplicatedStorage").GiveCoins.OnServerEvent:Connect(function(player)
	player.leaderstats.Claps.Value = player.Plus.Value * 10 + player.leaderstats.Claps.Value
	player.totalClaps.Value = player.Plus.Value * 10 + player.totalClaps.Value
end)

Level Up Scripts

local levelUp = game:GetService("ReplicatedStorage").LevelUp

local buyKey = game:GetService("ReplicatedStorage").BuyKey

levelUp.OnServerEvent:Connect(function(player)

player.leaderstats.Level.Value = player.leaderstats.Level.Value + 1

player.Plus.Value = player.Plus.Value + 1

end)

buyKey.OnServerEvent:Connect(function(player, value)

wait(2)

player.KeyLevel.Value = player.KeyLevel.Value + 1

player.leaderstats.Money.Value = player.leaderstats.Money.Value - value

end)
local levelUp = game:GetService("ReplicatedStorage").LevelUp
local player = game.Players.LocalPlayer

player.leaderstats.Claps:GetPropertyChangedSignal("Value"):Connect(function()
	if player.totalClaps.Value >= player.Plus.Value * player.Plus.Value * 1000 then
		local object = script.Parent.Frame
		levelUp:FireServer(player)
		object.Visible = true
		wait(2)
		object.Visible = false
	end
end)

1 Like

Your code doesn’t contain anything that may be faulty, Nothing in your code changes the values (except for when the player joins) and there’s nothing in your script to do with what you’ve just explained,

Perhaps you’ve supplied the wrong script?

2 Likes

Ok I will add some other scripts that might factor it.

1 Like

I added all the scripts that I would think change the system.

I’m still not seeing where the problem can be, you’ve added debounces etc.

I’m assuming it’s something wrong with this code

player.leaderstats.Claps:GetPropertyChangedSignal("Value"):Connect(function()
	if player.totalClaps.Value >= player.Plus.Value * player.Plus.Value * 1000 then
		local object = script.Parent.Frame
		levelUp:FireServer(player)
		object.Visible = true
		wait(2)
		object.Visible = false
	end
end)
if player.totalClaps.Value >= player.Plus.Value * player.Plus.Value * 1000 then

Your values mightn’t be what you think they are, Also, No need to run :GetPropertyChangedSignal,
Instead, you can do

player.leaderstats.Claps.Changed:Connect(function()

Would you be able to send a video of it happening? I think it might help me understand better.

1 Like

Roblox-2020-06-10-10-08-44

1 Like

Is Totalclaps the value that is showing on the screen or is claps that value?

The value on the screen is total claps (i am still uploading the other videos)

After resetting the data store it works.
Roblox-2020-06-10-10-11-42

But when I join back…

Roblox-2020-06-10-10-12-54

I am going to rejoin again and see what happens.

Edit: It does the same thing, just multiplying by a different value.

So from what i can see, The “plus” value is getting bigger, can you print out the value of “Plus” everytime you clap

game:GetService("ReplicatedStorage").GiveCoins.OnServerEvent:Connect(function(player)
	player.leaderstats.Claps.Value = player.Plus.Value * 10 + player.leaderstats.Claps.Value
	player.totalClaps.Value = player.Plus.Value * 10 + player.totalClaps.Value
print(player.Plus.Value)
end)

It’s either the script’s math is wrong or the plus value is constantly being made big.

2 Likes

Try change this code:

if success and data then
	Claps.Value = data[1]
	Level.Value = data[2]
	Plus.Value = data[3]
	Money.Value = data[4]
	totalClaps.Value = data[5]
	KeyLevel.Value = data[7]
else
	print("Data not found")
end
end)

to this:

if success and data then
	Level.Value = data[2]
	Plus.Value = data[3]
	Money.Value = data[4]
	totalClaps.Value = data[5]
    Claps.Value = data[1]
	KeyLevel.Value = data[7]
else
	print("Data not found")
end
end)
1 Like


Ok so how could I fix this.

Edit: I will try what you said

You appear to be levelling up many times over, It has to be something to do with

if player.totalClaps.Value >= player.Plus.Value * player.Plus.Value * 1000 then

This line here, If we plug in ordinary values for it: PlusValue = 1, TotalClaps = 0 (when you first join)
you will get
if 0 >= 1000 then

Which means, at one point, your totalclaps is greater than your plusvalue formula.

Try printing at the level up

player.leaderstats.Claps:GetPropertyChangedSignal("Value"):Connect(function()
	if player.totalClaps.Value >= player.Plus.Value * player.Plus.Value * 1000 then
        print("LeveledUp")		
        local object = script.Parent.Frame
		levelUp:FireServer(player)
		object.Visible = true
		wait(2)
		object.Visible = false
	end
end)

(Sorry for making you do so many things, i don’t deal with massive amounts of code well)

1 Like

I changed the data store key again to a whole new one. And I didn’t even clap but my stats look like this…

You must’ve punched in a previous datastore code and that happened.

I just smashed my keyboard so I don’t think that is why.
image

If that’s not the case, you want to debug the clap and level up function,

Let me know once you’ve added the print to the levels what it says.

1 Like


Currently it is working fine I will get to the leveling up part and fill you in.

1 Like