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

When a human toiches this model, it should move but its not?

Asked by 4 years ago

This is a normal script inside my model It doesn't work though!

function onTouched(hit)


local check = hit.Parent:FindFirstChild("Humanoid")
if check ~= nil then
    local user = game.Players:GetPlayerFromCharacter(hit.Parent)
    game.Workspace.Model:MoveTo(Vector3.new(0,0,0))
end 
0
Do you ever call the function? Rinextel 291 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

Touched events can only be done by parts not entire models. You can make a transparent brick with no collision and place it over the entire model. I rewrote some code for you. Just take note of where I've placed the trigger, just being a direct child of the model.

local touchtrigger = script.Parent.TouchPart --You can rename touchtrigger and TouchPart anything, just point it to the correct area. --
-- touchtrigger is the invisible brick that will activate the model to move when touched. --
function onTouched(hit)  
        script.Parent:MoveTo(Vector3.new(0,0,0))  -- I decided to use a script.Parent, that way you don't need to keep track of names.--
    end

touchtrigger.Touched:connect(onTouched) -- If you change "touchtrigger" at the top, you need to change it here too. --
0
Are you able to move a model with :MoveTo even when you don't have a PrimaryPart set? XD I forgot Dylan011444 59 — 4y
0
Thank you! Bssiemeow 30 — 4y
Ad

Answer this question