This is round 2 of this, because the first time I asked, I got no answers.
I made a script that goes inside a tool, so when you click, a flag-part in workspace moves to your mouse's position. It worked 100% until months and months ago when it just flat out broke, with no errors. Can someone please help me fix this?
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Tool = script.Parent local Ready = true local Flag = game.Workspace.WhiteFlag function click() if Ready == true then Ready = false Flag.Position = Mouse.Hit.p + Vector3.new(0,3,0) for i = 0, 1, .25 do Flag.Transparency = i wait(.25) end Ready = true end end Tool.Activated:connect(click)
Again, this worked before, and now doesn't throw errors. Simple fixes like "make sure you named parts right" and such will not assist.
Put this in a localscript, in either PlayerGui, or StarterPack!
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Tool = script.Parent local Ready = true local Flag = game.Workspace.WhiteFlag function click() if Ready == true then Ready = false Flag.Part.Position = Mouse.Hit.p + Vector3.new(0,3,0) for i = 0, 1, .25 do Flag.Part.Transparency = i wait(.25) end Ready = true end end Mouse.Button1Down:connect(function() click(Mouse) end)
Since you changed the position of the flag instead of the CFrame, it can appear on top of something unexpected. So, I've tidied it up and changed/added a few bits.
local Tool = script.Parent local Ready = true local Flag = game.Workspace.WhiteFlag function click(mouse) if Ready == true then Ready = false if mouse.Hit ~= nil then -- Make sure you aren't wanting to place the flag in the sky (derp) Flag.CFrame = mouse.Hit + Vector3.new(0,3,0) -- Changes the CFrame instead of the position so the flag doesn't unexpectedly appear on the top of a building if you try to place it inside for i = 0, 1, .25 do Flag.Transparency = i wait(.25) end end Ready = true end end Tool.Equipped:connect(function(mouse) mouseConnection = mouse.Button1Down:connect(function() click(mouse) end) -- Calls the click function with the PlayerMouse whenever you click end tool.Unequipped:connect(function() mouseConnection:disconnect() -- Disconnects mouseConnection so that you can click freely without the tool selected end
It should work now. If you have any questions, contact me.