Points Adding Back After Subtraction

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)

I tried that before, but it says attempt to index nil with ‘Transparency’

show the script then as that should work

I dont know whayt you mean by that?


game.ReplicatedStorage.PointSubtraction.OnClientEvent:Connect(function(player,v)
	
	v.Transparency = 0.5
	v.CanCollide = false
	wait(1)
	v.Transparency = 0
	v.CanCollide = true
	
	
end)

remove player from that script
NOT the other one

Thanks so much! Is there any way I can pay you some robux?

dude u don’t have to it was free cause on devforum