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

How Can I Make This Touched Function Work Properly in Normal Servers?

Asked by 8 years ago
Edited 8 years ago

How can I make this touched function work in normal servers? There are two simple scripts: One script is located in ServerScriptService which creates the falling parts, and it inserts the second script into each part. The second script is located in ServerStorage, and it has a simple onTouched function:

script.Parent.Touched:connect(function(hit)
    if hit.Anchored then
        script.Parent.Anchored = true
        script.Parent.RotVelocity = Vector3.new(0, 0, 0)
        script:Destroy()
    end
end)

All the scripts function great when I play in Roblox Studio. Here is a GIF showing how it is suppose to work: http://www.giphy.com/gifs/3oz8xXd07rTffQokEw However, when I play in a server, some parts anchor mid air, and sometimes the touched script does not change the RotVelocity to (0, 0, 0). Here is another GIF illustrating how messed up the game is: http://www.giphy.com/gifs/l0HluLPMclF5GTOOk Why is this happening? Is there a way to make it work like when I play in Roblox Studio? Thank you for reading this!

1 answer

Log in to vote
1
Answered by
nanaluk01 247 Moderation Voter
8 years ago
Edited 8 years ago

I believe you get this problem because your parts gets anchored whenever anything hits them.

To fix this, you need to check if the object the part is hitting is the BasePlate.

To do this, you simply have to do this:

script.Parent.Touched:connect(function(hit)
    if hit.Anchored then
        if hit.Name == "Baseplate" then   --Checks if the part hits BasePlate
            script.Parent.Anchored = true
                script.Parent.RotVelocity = Vector3.new(0, 0, 0)
                script:Destroy()
        end
    end
end)

If this helped you, make sure you accept the answer!

0
Did you watch the GIFs? It works normally in Roblox Studio, so that is not the problem. I think it is the touch script functions slow. Thanks for trying though! I upvoted. ;3 GatitosMansion 187 — 8y
Ad

Answer this question