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

why doesn't my script work?[positioning]



function onClick (mouse)
	local Part = script.Parent.Part:Clone()
	Part.Parent = game.Workspace
	Part:MoveTo(mouse.hit.p)

end



function onEquipped (k)
	k.Button1Down:connect(onClick)
end

script.Parent.Equipped:connect(onEquipped)


i tried to make a script that gets the part out of the tool itsself and put it in the workspace and on the place where the players has clicked

this script is put in a tool this is a normal script

how can i fix it that it clones a part in the workspace where the player has clicked

1 comment

0

Try changing the position property of your part don't use the :MoveTo method with parts it's more efficient to just do something like... Part.Position = mouse.hit.p

1 answer

function onClick (mouse)
    local Part = script.Parent.Part:Clone()
    Part.Parent = game.Workspace
    Part:MoveTo(mouse.hit.p)

end



function onEquipped (k)
    k.Button1Down:connect(onClick)
end

script.Parent.Equipped:connect(onEquipped)

First of all, you shouldn't put a space after the function name. To me it just looks weird and it may even break your script. About your actual problem: You have defined the event locally INSIDE another event and thus you also have to put your function inside.

function onEquipped(k)
    function onClick (mouse)
    local Part = script.Parent.Part:Clone()
    Part.Parent = game.Workspace
    Part:MoveTo(mouse.hit.p)

end
    k.Button1Down:connect(onClick)
end

script.Parent.Equipped:connect(onEquipped)

Hope this helps! If you got any questions, feel free to ask!

6 comments

0

it works exactly like my script

0

the problem is that it doesn't go to the position of the mouse

0

No. I explained the difference between your version and mine. If it still doesn't work, show me the output.

0

Well, why didn't you say this in your question?

0

Tip: You can not get a player's mouse from a Server Script, you need to use a Local Script.

0

i put my script in the local script thats in the tool     but stil gives the same outcome as my previous script

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