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

i made a script that will make the player move when u click and it didn't work, can anyone help me?

Asked by 3 years ago
Edited 3 years ago

the error starts below here


local function MoveCharacter(lookVector, MoveDis) game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(char) local humanoidRootPart = char.HumanoidRootPart if humanoidRootPart then humanoidRootPart.CFrame = humanoidRootPart.CFrame + (lookVector.CFrame.LookVector * MoveDis) end end) end) end local function ActivateClickDetector (MyClickDetector, MyLookVector, MoveLength) MyClickDetector.MouseClick:Connect(function(mousClick) if mousClick then CameraPrimaryPart.CFrame = CameraPrimaryPart.CFrame +(MyLookVector.CFrame.LookVector * MoveLength) CameraPrimaryPart.Orientation = MyLookVector.Orientation MoveCharacter(MyLookVector, MoveLength)--here it didn't work, idk why, there is no error in the output print("ClickDetector works fine") end end) end ActivateClickDetector(StraightArrowclickDetec, straightArrLookVec, 50) ActivateClickDetector(DiagonalLArrowclickDetec, diagonalLArrLookVec, 50) ActivateClickDetector(DiagonalRArrowclickDetec, diagonalRArrLookVec, 50)
0
Just want to say English is not my main language so the variables might sound a little cringe daokhiethy 25 — 3y
0
this is the first time i post something so it looks pretty ugly daokhiethy 25 — 3y
0
finally i know how to identify the script and normal texts daokhiethy 25 — 3y

1 answer

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

Your script is wrong and you will have to rewrite it. The problem is that you're connecting events in functions instead of connecting functions to events.

Here is a function connected to an event.

function example()
    print("function ran")
end

Object.Event:Connect(example)

What you're doing is similar to this:

function example()
    Object.Event:Connect(function()
        print("function ran")
    end)
end

Here's how your script should look like:

function moveCharacter(lookVector, moveDis, player) -- extra player variable
    local character = player.Character
    if character and character.HumanoidRootPart then
        -- do stuff
    end
end

ClickDetector1.MouseClick:Connect(function(player)
    -- do camera stuff
    moveCharacter(lookVector, moveDis, player)
end)

On lines 02 to 09, what you're actually doing is waiting for another player to join, then waiting for their character to be loaded in, and then you are making them move. Which is not what you want to do.

0
thanks bro daokhiethy 25 — 3y
Ad

Answer this question