Why does it not check?

Hello, making a simple check to see if the value inside of the players’ character is there, however it prints “did not find anything” in the output. Can someone help? Thanks. Here is my current code:

game.ReplicatedStorage.TPOnDeath.OnServerEvent:Connect(function(plr,stage)
	task.wait(0.05)
	print('recieved and waiutedg')
	if plr.Character:FindFirstChild('StageTransferValue').Value == tonumber(stage) then
		print('found?')
		for _,v in pairs(workspace.Checkpoints:GetChildren()) do
			print('looped')
			if tostring(plr.Character:FindFirstChild('StageTransferValue').Value) == v.Name then
				print('foudn amtch')
				plr.Character:PivotTo(v.CFrame + Vector3.new(0,2,0))
				print('tptpepdpl')
			end
		end
	else
		print('did not find anything')
	end
end)

Is StageTransferValue being changed on the Server? Also, is it made on the ServerSide ?

No, it is being changed by a local script, BUT it is through a remote event. Yes on the other.

I am confused because you are asking if the StageTransferValue is equal to the value you sent via Remote Event, but if it’s changed on the Client, then it would never appear on the Server as changed.

Sorry if i worded it wrong lol its late at night. I’ll send a picture. The value IS being changed:

edit: oops, forgot to include the value changed script for the value: here it is

function playerAdded(plr)
	print(plr.Name)
	plr.CharacterAdded:Connect(function()
		local char = plr.Character
		local val = Instance.new("IntValue")
		val.Name = "StageTransferValue"
		val.Parent = char
	end)
end

function setNum(plr,valName)
	local tag = plr.Character:FindFirstChild('StageTransferValue')
	tag.Value = tonumber(valName)
end

game.Players.PlayerAdded:Connect(function(plr)
	playerAdded(plr)
end)

for _,v in pairs(workspace.Checkpoints:GetChildren()) do
	v.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild('Humanoid') then
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			setNum(plr,v.Name)
		end
	end)
end

You should put the StageTransferValue in the Player, since once the Character dies the Values gets destroyed and the value would be set back to 0.

Maybe try printing Stage on the ServerEvent?

Nope, resetted like 3 times, still says the same.

Did you print Stage on the ServerEvent?

have not, lemme try it rn.

edit; IT SOMEHOW WORKS NOW?? I really didn’t change like anything and it wasn’t working when i created this topic. Thank you guys for your time :smiley:

Try this:

game.ReplicatedStorage.TPOnDeath.OnServerEvent:Connect(function(plr,stage)
	task.wait(0.05)
	print('recieved and waiutedg')
    local StageTransferValue = plr.Character:FindFirstChild('StageTransferValue')
	if StageTransferValue  and StageTransferValue .Value == tonumber(stage) then
		print('found?')
		for _,v in pairs(workspace.Checkpoints:GetChildren()) do
			print('looped')
			if tostring(plr.Character:FindFirstChild('StageTransferValue').Value) == v.Name then
				print('foudn amtch')
				plr.Character:PivotTo(v.CFrame + Vector3.new(0,2,0))
				print('tptpepdpl')
			end
		end
	else
		print('did not find anything')
        print(StageTransferValue)
	end
end)

Oh nevermind

1 Like

Sorry!! I really appreciate the time you took for this script though.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.