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?
I think this will work:
Leaderboard script (ServerScriptService)
01 | game:GetService( "Players" ).PlayerAdded:Connect( function (player) |
02 | local leaderstats = Instance.new( "Folder" ) |
03 | leaderstats.Name = "leaderstats" |
04 | leaderstats.Parent = player |
05 |
06 |
07 | local points = Instance.new( "IntValue" ) |
08 | -- Name to what it's called |
09 | points.Name = "Points" |
10 | points.Parent = leaderstats |
11 | points.Value = 0 |
12 | end ) |
Teleport script (Part)
01 | -- Points needed to teleport: |
02 | local POINTS_NEEDED_TO_TELEPORT = 14 |
03 |
04 | -- Name to the part you want to teleport to |
05 | local TeleportPart = workspace.Teleport |
06 |
07 | local function teleport(character, part) |
08 | character.HumanoidRootPart.CFrame = part.CFrame + Vector 3. new( 0 , 5 , 0 ) |
09 | end |
10 | script.Parent.Touched:Connect( function (hit) |
11 | local hum = hit.Parent:FindFirstChildOfClass( "Humanoid" ) |
12 | if hum then |
13 | local player = game:GetService( "Players" ):GetPlayerFromCharacter(hit.Parent) |
14 | if player then |
15 | local leaderstats = player:FindFirstChild( "leaderstats" ) |
Tell me if it doesn't work.
Here's the code, hope its helping you :)
Leaderstats script :
01 | local plrs = game:GetService( "Players" ) |
02 |
03 | plrs.PlayerAdded:Connect( function (p) |
04 |
05 | local LS = Instance.new( "Folder" ) |
06 | LS.Name = "leaderstats" |
07 | LS.Parent = p |
08 |
09 | local Value = Instance.new( "IntValue" ) |
10 | -- Change the string to anything you desired |
11 | Value.Name = "Value" |
12 | Value.Value = 0 |
13 | Value.Parent = LS |
14 | end ) |
Teleport script :
01 | local plrs = game:GetService( "Players" ) |
02 |
03 | -- Change the Value of the Variable to anything you desired |
04 | local valueneed = 1 |
05 |
06 | -- Put the script into the part or change it to "workspace.(YOUR PART'S NAME)" |
07 | local tpPart = script.Parent |
08 |
09 | -- Change this to the "endPos" to Part's name |
10 | local endPos = workspace.endPos |
11 |
12 | function tp(char, pos) |
13 | char:PivotTo(char:GetPivot() * pos.CFrame) |
14 | end |
15 |
If not work, tell me.