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

Areas Not Working? Even Though You Have Enough Rebirths?

So I have this area system and when you have enough rebirths you can go to the next area and removes the GUI. But right now it removes the GUI but you still get teleported back to spawn.

Here's the script!

script.Parent.Touched:Connect(function(hit)
    local debounce = false
	
	if hit:IsA("BasePart") then
	    if game.Players:FindFirstChild(hit.Parent.Name)["leaderstats"].Rebirths.Value >= 2 then
	        debounce = false
	    else if game.Players:FindFirstChild(hit.Parent.Name)["leaderstats"].Rebirths.Value <= 1 	then
	            if hit.Parent:FindFirstChild("Humanoid") then
	                hit.Parent.Head.CFrame = CFrame.new(game.Workspace.SpawnTP.Position)
	            end
	        end
	    end
	end
end)

6 comments

0

elseif*

0

Still doing it

0

what do u mean teleported back to spawn

0

i have a teleport system where if you dont have enough you get teleported back i think the issue is that its not realizing the rebirths changed

0

are u changing the rebirth values from the client or server

0

also use game.Players:GetPlayerFromCharacter(hit.Parent) instead of :FindFirstChild(hit.Parent.Name) in an if statement

1 answer

Ok so here are some of the problems I see:

  1. The debounce = false twice doesn't do anything, so i adjusted that portion accordingly.
  2. You have else (space) if instead of elseif, so that would be one problem.
  3. When moving a character, it is generally better to alter their HumanoidRootPart CFrame position, rather than the Head since the HumanoidRootPart is the PrimaryPart of the Model.
  4. You also need to change the CFrame to another CFrame, rather than the CFrame to a Position. With this in mind, I revised your script to the following code in a Server Script (preferably in ServerScriptService):
local debounce = false

script.Parent.Touched:Connect(function(hit)
if debounce == true then return end
debounce = true

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local rebirth = player["leaderstats"].Rebirths.Value

	if rebirth >= 2 then
		hit.Parent.HumanoidRootPart.CFrame = workspace.SpawnTP2.CFrame
	elseif rebirth <= 1 then
		hit.Parent.HumanoidRootPart.CFrame = workspace.SpawnTP.CFrame
	end
	
debounce = false
end)

I chose the name "SpawnTP2" since obviously the spawn cannot be the same for both. If you need an offset for the CFrames, you can do the following:

			hit.Parent.HumanoidRootPart.CFrame = game.Workspace.SpawnTP.CFrame + Vector3.new(0, 0, 0)

EDIT: 5. Removed CFrame.new(), Removed redundant Humanoid checks

21 comments

0

Its still doing the same thing

0

Alright, well then let me edit it a bit give me a sec

0

actually im pretty sure the Head is the primary part of r15 avatars

0

also use game.Players:GetPlayerFromCharacter() instead of using :FindFirstChild()

0

I always use the head whether or not its r15 or r6

0

theres a chance of the character getting stuck into the ground by setting the head's position, since pretty much the entire character is going to be in the parts underneath it

0

true

0

and you add a Vector3 offset outside of the CFrame.new() constructor

0

EXpodo can you answer the question pls

0

since the other arguments are lookvectors and stuff, and you cant do that anyways

0

I wrote about the Vector3 offset, also, i fixed it

0

uh u didnt?

0

also CFrame.new() takes in a vector3 value, not a cframe value

0

i removed the CFrame.new() portions, well it works now so

0

also checking if :FindFirstChild() returns nil is redundant

0

I used the functions he did originally, if he wants them to be more efficient, then he can change them

0

but your suppose to improve the OP's code

0

yes, i understand, I made those adjustments, though i kinda find it odd to have the whole string in one line like in rebirths

0

Ye nothings working

0

When I tried it, it worked for me, so make sure that you have the correct parentage for SpawnTP and SpawnTP2, i also used a Server Script in ServerScriptService if that changes anything. Also where is the script.Parent located?

0

why are you using Game.Workspace

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