How to make a teleporter that verifies if a value is right?

okay so, i tested it out… its working until line 5 of the server code, i updated the local script to detect when the part is touched too, for some reason just had to rewrite.

local rp = game:GetService("ReplicatedStorage")
local debounce = false

workspace.bruh.Touched:Connect(function()
	print("brothatcool")
	if debounce == false then
		print("thisisaredumb")
		debounce = true
		rp.RemoteEvent:FireServer()
		wait(5)
		debounce = false
	end
end)

edit: expirimenting with server code

But that doesn’t change anything, How I referenced my part was by doing script.Parent.Touched:Connect etc…

made a script that works!

Insert this into the part:

script.Parent.Touched:Connect(function(h)
local hum = h.Parent:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(h.Parent)
if player.leaderstats.Wins.Value <= 0 then
h.Parent.HumanoidRootPart.CFrame = h.Parent.HumanoidRootPart.CFrame + Vector3.new(0,10,0)
end
end)
1 Like

nope, sorry but the game won’t agree that leaderstats exist somehow

yeah my script works… also that really should work, works with me, you need to make sure the part has streaming enabled = true and i added some prints, increased the value and it worked

also you should make sure leaderstats exists by checking the name of your thing containing wins, and if it is then :WaitForChild()

How bout you show us your leaderstats script?

This is the script I got from you (modified). None of the Prints work
LocalScript:

local rp = game:GetService("ReplicatedStorage")
local debounce = false

script.Parent.Touched:Connect(function()
	print("Part touched")
	if debounce == false then
		print("DebounceFalse")
		debounce = true
		rp.WinnersTeleport:FireServer()
		wait(5)
		debounce = false
	end
end

Script:


ReplicatedStorage.WinnersTeleport.OnServerEvent:Connect(function(player)
	print("Received Remote")
	if player.leaderstats.Wins.Value < 0 then
		print("If/else Done")
		player.Character.HumanoidRootPart.CFrame = CFrame.new(0,0,0)
	end
end)

Try make copy this script into a script in ServerScriptService:

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

    local wins = Instance.new("IntValue")
    wins.Name = "Wins"
    wins.Parent = leaderstats
    wins.Value = 0
end)

Leaderboard script is ^^^^ so you know

This is leaderstats in SSS. Please ignore the useless stuff

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

game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Points = Instance.new("IntValue")
	Points.Name = "Points"
	Points.Parent = leaderstats
	
	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"
	Wins.Parent = leaderstats
	
	local Activations = Instance.new("IntValue")
	Activations.Name = "Activations"
	Activations.Parent = leaderstats
	
	local Deaths = Instance.new("IntValue")
	Deaths.Name = "Deaths"
	Deaths.Parent = leaderstats
	
	-->> Items: Items equipped
	
	local ToolEquipped1 = Instance.new("StringValue")
	ToolEquipped1.Name = "ToolEquipped1"
	ToolEquipped1.Parent = player
	
	local ToolEquipped2 = Instance.new("StringValue")
	ToolEquipped2.Name = "ToolEquipped2"
	ToolEquipped2.Parent = player
	
	local ToolEquipped3 = Instance.new("StringValue")
	ToolEquipped3.Name = "ToolEquipped3"
	ToolEquipped3.Parent = player
	
	-->> Items: Items owned and unowned
	
	local ItemsOwned = Instance.new("Folder")
	ItemsOwned.Name = "ItemsOwned"
	ItemsOwned.Parent = player
	
	local LoveSignOwned = Instance.new("BoolValue")
	LoveSignOwned.Name = "LoveSignOwned"
	LoveSignOwned.Parent = ItemsOwned
	
	local ShoeBoxOwned = Instance.new("BoolValue")
	ShoeBoxOwned.Name = "ShoeBoxOwned"
	ShoeBoxOwned.Parent = ItemsOwned
	
	-->> Data: Begining
	
	local playerUserId = "Player_"..player.UserId
	
	-->>Data: Load Data
	
	local data
	local success, errormessage	 = pcall(function()
		data = myDataStore:GetAsync(playerUserId)
	end)
	
	if success then
		if data then
			Points.Value = data.Points
			Wins.Value = data.Wins
			Activations.Value = data.Activations
			Deaths.Value = data.Deaths
			--Items Owned
			LoveSignOwned.Value = data.LoveSignOwned
			ShoeBoxOwned.Value = data.ShoeBoxOwned
		end
	end
	
end)

-->> Data: Saving Stats

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

	local data = {
		Points = player.leaderstats.Points.Value;
		Wins = player.leaderstats.Wins.Value;
		Activations = player.leaderstats.Activations.Value;
		Deaths = player.leaderstats.Deaths.Value;
		-- Items Owned
		LoveSignOwned = player.ItemsOwned.LoveSignOwned.Value;
		ShoeBoxOwned = player.ItemsOwned.ShoeBoxOwned.Value;
	}
	
	local success, errormessage = pcall(function()
		myDataStore:SetAsync(playerUserId, data)
	end)
		
	if success then
		print("Data succefully saved!")
	else
		print("Data saving error")
		warn(errormessage)
	end
	
end)

Ahh! Try set a default value to Wins like:

wins.Value = 0

I will try but how will that change?

Edit: Nothing happened, same as before…

Hmm. I just tried it in my own studio, and worked.

This is odd.

local scripts dont run in workspace… its a starter pack script :roll_eyes:

Hold up, so it has to be in the starter pack?

If you wanted to teleport the player if they had 1 win or more, then why did you make it less than or equal to 0 instead of greater than 0?

1 Like

I CAN’t BELIEVE IT!!! This was it all along…

This actually works, it was just the symbol that had to be >

1 Like

Ah of course!

Make sure to mark a solution!

Thanks @sympoll

1 Like

Glad I was able to help :smiley:

2 Likes