Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)




3 comments

0

Just want to say English is not my main language so the variables might sound a little cringe

0

this is the first time i post something so it looks pretty ugly

0

finally i know how to identify the script and normal texts

1 answer

✓ Accepted answer

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.

1 comment

0

thanks bro

This discussion is preserved as it was. New answers, comments, and votes are closed.