Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Areas Not Working? Even Though You Have Enough Rebirths?

Asked by 5 years ago

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)
0
elseif* WideSteal321 773 — 5y
0
Still doing it iiDev_Hunt3r 64 — 5y
0
what do u mean teleported back to spawn User#23365 30 — 5y
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 iiDev_Hunt3r 64 — 5y
View all comments (2 more)
0
are u changing the rebirth values from the client or server User#23365 30 — 5y
0
also use game.Players:GetPlayerFromCharacter(hit.Parent) instead of :FindFirstChild(hit.Parent.Name) in an if statement User#23365 30 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

0
Its still doing the same thing iiDev_Hunt3r 64 — 5y
0
Alright, well then let me edit it a bit give me a sec SerpentineKing 3885 — 5y
0
actually im pretty sure the Head is the primary part of r15 avatars User#23365 30 — 5y
0
also use game.Players:GetPlayerFromCharacter() instead of using :FindFirstChild() User#23365 30 — 5y
View all comments (17 more)
0
I always use the head whether or not its r15 or r6 iiDev_Hunt3r 64 — 5y
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 User#23365 30 — 5y
0
true iiDev_Hunt3r 64 — 5y
0
and you add a Vector3 offset outside of the CFrame.new() constructor User#23365 30 — 5y
0
EXpodo can you answer the question pls iiDev_Hunt3r 64 — 5y
0
since the other arguments are lookvectors and stuff, and you cant do that anyways User#23365 30 — 5y
0
I wrote about the Vector3 offset, also, i fixed it SerpentineKing 3885 — 5y
0
uh u didnt? User#23365 30 — 5y
0
also CFrame.new() takes in a vector3 value, not a cframe value User#23365 30 — 5y
0
i removed the CFrame.new() portions, well it works now so SerpentineKing 3885 — 5y
0
also checking if :FindFirstChild() returns nil is redundant User#23365 30 — 5y
0
I used the functions he did originally, if he wants them to be more efficient, then he can change them SerpentineKing 3885 — 5y
0
but your suppose to improve the OP's code User#23365 30 — 5y
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 SerpentineKing 3885 — 5y
0
Ye nothings working iiDev_Hunt3r 64 — 5y
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? SerpentineKing 3885 — 5y
0
why are you using Game.Workspace greatneil80 2647 — 5y
Ad

Answer this question