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

How can I fix my code for unfreezing the player?

Asked by 3 years ago
Edited 3 years ago

I'm making a basketball court game. So I have a block that on touch freezes the character in order to keep them on a team spot, but if they want to exit they can, but I need them to be unfrozen, of course. This is my code for the block that will unfreeze them, but it won't unfreeze:

function touched(part)
    if not game.ReplicatedStorage.RemoteEvent then end
    if part.Parent:FindFirstChild('Humanoid') then
        local n = part.Parent
        local all = n:GetChildren()
        for i=1,#all do
            if all[i]:IsA("Part") then
                all[i].Anchored = false
            end
        end
    end
end

script.Parent.Touched:Connect(touched)

If anyone could help me figure this out it would be much appreciated! I'm very new to scripting.

1
try GetDescendants() instead of GetChildren(), doubt it will make a difference but you might have a custom character. Also check for errors, also I'm pretty sure if you have mesh parts and unions in the user, those will stay anchored. greatneil80 2647 — 3y
0
Didn't work sadly. I appreciate the suggestion so thank you, but the character is not a custom character either. I should have stated that the freeze is the same script but all that is changed for the unfreeze part and freeze part is whether Anchored = true or false. CameUpFromNothing 37 — 3y
0
@CameUpFromNothing, what doesn't work in your script? Explain more in your question, with what your goal is with examples etc. JesseSong 3916 — 3y
0
Make sure you send us your whole script. JesseSong 3916 — 3y
View all comments (2 more)
0
That's the entire script, and what I described was the exact problem. I don't really know what else to say. CameUpFromNothing 37 — 3y
0
idk, the code looks fine to me JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Problem: Your problem is using :IsA"Part". Most of the parts in the character aren't parts. They are meshparts. But some can still be parts..

Solution: To resolve this, use the highest class which includes them all: basepart.

Use IsA"BasePart", this I think will fix your problem unless there's more than 1 problem. Which in that case, something would have to be terribly wrong like the wrong character something but that's unlikely.

Suggeations: I suggest you look at things more closely, see what your working with. You tried to look in the character for things with the class name "Part", well, if it doesn't work, you should have looked din the character manually to see if what is in the character are what you think is there, which in this case it's not, you would have seen that they are meshparts if you checked. Please do this in the future.

Hope this helps :3

Ad

Answer this question