Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script tells that value is 0 even though the value is greater than 1?

Hi so i am a making a script where if a player touches a part it takes the value of 'souls' and adds it to the 'Qu' (currency) but even though the value of 'souls' is greater then 1 in the leader board the script returns the value as 0

heres the code:

 local sellPad = script.Parent["Sell Parts"].SellPart
 local quValueGui = game.StarterGui.quGui.quValueGui
 local soulsValueGui = game.StarterGui.soulsGui.soulsValueGui
 sellPad.Touched:Connect(function(hit)
	local H = hit.Parent:FindFirstChild("Humanoid")
 	if H then
 		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
 		if player then
 			local leaderstats = player:WaitForChild("leaderstats")
 			local souls = leaderstats.Souls
 			local qu = leaderstats.Qu
 			if souls.Value >= 0 then
 				print(souls.Value)
 				qu.Value = souls.Value + qu.Value
				quValueGui.Text = qu.Value
			end
 			if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 34956109) then
				if souls.Value > 0 then
 					qu.Value = souls.Value + qu.Value * 2
					quValueGui.Text = qu.Value
 				end
 			end
 		end
	end
 end)

this is the script for updating the values everytime u click:

 local cooldown = false
 game:GetService("UserInputService").InputBegan:Connect(function(input, engine_processed) if engine_processed then return end
 
 local player = game.Players.LocalPlayer
 local soulsGui = game.Players.LocalPlayer.PlayerGui.soulsGui.soulsValueGui
 local leaderstats = player:WaitForChild("leaderstats")
 local souls = leaderstats.Souls
 local qu = leaderstats.Qu
 local values = {
 	game.Workspace.coffinValues.woodCoffin.Value,
 	game.Workspace.coffinValues.ironCoffin.Value,
 	game.Workspace.coffinValues.goldCoffin.Value
 }
 
 if cooldown == false then
 	
 	if input.UserInputType == Enum.UserInputType.MouseButton1 then
 		cooldown = true
 		soulsGui.Text = soulsGui.Text + values[1]
 		souls.Value = souls.Value + values[1]
		wait(0.5)
		cooldown = false
 	end
 end
 
 if cooldown == false then
 	if input.UserInputType == Enum.UserInputType.Touch then
		cooldown = true
 		soulsGui.Text = soulsGui.Text + values[1]
 		souls.Value = souls.Value + values[1]
 		wait(0.5)
 		cooldown = false
	end
 
 end
 end)
 
 wait(2)
 cooldown = false

the selling pad works when i increase the value by stepping on a part but when i click and it increases it always returns the value as 0 even though the value is more than 1

the increase by clicking script is a local script and the selling pad is a server script

1 answer

The issue is due to filtering enabled (FE).

Filtering Enabled prevents changes on the client to replicate to the server to prevent exploiters from manipulating the server from their client; this is the reason why the server is saying that the value is 0, if you were to print the value on the client after changing it, it would print the value you're changing it to.

So, to fix this, you will need to change the value on the server, you can do that by using a RemoteEvent and firing it when you need to change the value.

This discussion is preserved as it was. New answers, comments, and votes are closed.