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

How do I make a teleporter depending on leaderstats?

So I have this game with dimensions, How do I make it so if you have for instance 14 “points” in the leader stats, then you can be able to touch a specific part and teleport to a place?

(Basically, you can only teleport to this place by touching a part and it will only teleport you if you have for example 14 points in the leader stats), how do I make that?

2 answers

✓ Accepted answer

I think this will work:

Leaderboard script (ServerScriptService)

game:GetService("Players").PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	

	local points = Instance.new("IntValue")
	-- Name to what it's called
	points.Name = "Points"
	points.Parent = leaderstats
	points.Value =0
end)

Teleport script (Part)

-- Points needed to teleport:
local POINTS_NEEDED_TO_TELEPORT = 14

-- Name to the part you want to teleport to
local TeleportPart = workspace.Teleport

local function teleport(character, part)
	character.HumanoidRootPart.CFrame = part.CFrame + Vector3.new(0,5,0)
end
script.Parent.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
	if hum then
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
		if player then
			local leaderstats = player:FindFirstChild("leaderstats")
			if leaderstats then
				local points = leaderstats:FindFirstChild("Points")
				if points then
					if points.Value >= POINTS_NEEDED_TO_TELEPORT then
						 teleport(hit.Parent, TeleportPart)
					end
				else
					warn(tostring(player), "does not have points!")
				end
			else
				warn(tostring(player),"does not have leaderstats!")
			end
		end
	end
end)

Tell me if it doesn't work.

1 comment

0

I'll try it and let you know, thank you so much!

Here's the code, hope its helping you :)

Leaderstats script :

local plrs = game:GetService("Players")

plrs.PlayerAdded:Connect(function(p)
	
	local LS = Instance.new("Folder")
	LS.Name = "leaderstats"
	LS.Parent = p

	local Value = Instance.new("IntValue")
	-- Change the string to anything you desired
	Value.Name = "Value" 
	Value.Value = 0
	Value.Parent = LS
end)

Teleport script :

local plrs = game:GetService("Players")

-- Change the Value of the Variable to anything you desired
local valueneed = 1

-- Put the script into the part or change it to "workspace.(YOUR PART'S NAME)"
local tpPart = script.Parent

-- Change this to the "endPos" to Part's name
local endPos = workspace.endPos

function tp(char, pos)
	char:PivotTo(char:GetPivot() * pos.CFrame)
end

tpPart.Touched:Connect(function(h)
	local p
	local LSValue

	if h.Parent:IsA("Model") or h:FindFirstAncestorOfClass("Model") then
		
		if h.Parent:FindFirstChild("Humanoid") then
			p = plrs:GetPlayerFromCharacter(h.Parent)
			LSValue = p.leaderstats.Value 
			
			if LSValue.Value >= valueneed then
				tp(h.Parent, endPos)
			elseif LSValue.Value <= valueneed then
				print("The value is not enough")
			elseif p.leaderstats == nil then
				print("Leaderstats are not found!")
			end
		end
	end
end)

If not work, tell me.

3 comments

0

...

0

I'll try it and let you know if it doesn't work, thank you so much!!

0

btw echo, u can tell me if there's any copy of it

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