Points Adding Back After Subtraction

I’m a little lost in this thread, but heading back to the original problem, you said the value keeps jumping back up correct? I presume the problem is related to this line of code being ran in a local script.

You need to change datastore values via the server and not the client. This is because it is local (in the name), while changing on the server will be a global change. I suggest finding some way to notify the server for when a user touches the door and change the value through a server script.

Multiple mistakes, you mean. I told you all of them.

Dude I found the error and why it’s not working

He is using variables, called FuncVrbs, which is short.

They only reconize stats. Thats why if you type leaderstats it would not display on the leaderboard.

task.wait() is used for pairs

NO he is not the problem is he is using A LOCAL SCRIPT FOR SERVER SCRIPTED VARIABLES.

I would recommend you stop replying as your replies aren’t contributive and spread false information.

Yes it does? I use this in my game and it works fine.

So I guess a Roblox Staff member is wrong?

2 Likes

I have seen them in multiple posts and each time the code has massive flaws

I suggest you have a look at how the programming works and revise it a bit

Ok thanks, but whenever I used a remote event it says Value is not a valid member of Player. Im presume this is becuase I am using local script values, but Im not really sure how I would go about this.

local repStor = game:GetService("ReplicatedStorage")
local PointSubtraction = repStor:WaitForChild("PointSubtraction") 

PointSubtraction.OnServerEvent:Connect(function(plr, door)
	plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - door.Value.Value
end)

I don’t think a remote event is actually necessary for this. You can use the Touched event via a server script and grab the player based on the parameter it provides.

I copied the script over, but it only runs once and can never be runned again. :man_shrugging:

local Workspace = game:GetService("Workspace")
local door = Workspace.Door

door.Touched:Connect(function(hit)
	local human = hit.Parent:FindFirstChild("Humanoid")
	if human ~= nil then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr.leaderstats.Points.Value >= door.Value.Value then
			script.Enabled = false
	plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - door.Value.Value
		end
	end
end)

I assume that was intended since you disable the script here. Some stuff to take note of though.

1.) Check to make sure whatever touches the door is a player
2.) I would destroy the door rather than disabling the script if that is possible (through the client)
3.) Since you have multiple doors, instead of putting this script into each one, use a for loop.

Ok Collin here is what you want to do:

Make a remote event in replicated storage

Server Script:

game.Players.PlayerAdded:Connect(function(p)
	
	local leaderstats = Instance.new("IntValue", p)
	leaderstats.Name = "leaderstats"
	
	local wins = Instance.new("IntValue", leaderstats)
	wins.Name = "Wins"
	
	local Points = Instance.new("IntValue", leaderstats)
	Points.Name = "Points"
	local x = wins.Value
	Points.Value = 0
	
	
	while true do
		Points.Value += 1 + wins.Value
		task.wait(1)
	end
end)

game.Workspace.Door.Touched:Connect(function(hit)

 if hit.Parent and hit.Parent:FindFirstChild("HumanoidRootPart") then
         local value = door.Value
         local player = game.Players:GetPlayerFromCharacter(hit.Parent)
         local leaderstats = player.leaderstats
        local points = leaderstats.Points
        if points.Value - value.Value >= 0 then

        points.Value -= value.Value
         game.ReplicatedStorage.[eventname]:FireClient(player)
        end
   end
end)


local script:

local door = game.Workspace.door

game.ReplicatedStorage.[eventname].OnClientEvent:Connect(function()

 door.Transparency = 0.5
door.CanCollide = false
wait(1)
door.Transparency = 0
door.CanCollide = true

end)

2 Likes

You can add in a bool value named open and then if it is false on the server side all it does is set it to true fires the event waits 1.1 seconds and sets it to false

I added this to the serverscript
+ and door.Open == false
And turned it on and off in the local script.

However, doing this made the script stop working and showed no errors.

don’t do it on the local script do it on the server script and it should be door.Open.Value = false/true

Thanks it work flawlessly on one door , but how would I make it so if I wanted multiple doors at differnt prices?

put the doors in a folder then you can do like

for i,v in pairs(game.Workspace.Doors:GetChildren()) do

     v.Touched:Connect(function(hit)
 
         --continue the code for the touched event in here
         -- when firing the event after the player do the door itself so v

     end)
end

in the local script just replace the door variable with the door model you gave in the evemt

Im not sure how to send the variable over lol. I tried used an arguement to send v over when I fire the remote event, but it says it has to be a player.

just do in the remote (player,v)