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

Flag placing script won't work?

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.

2 answers

✓ Accepted answer

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)

3 comments

0

what's different? You may have the scripting down, but the 'helpers' part doesn't work if you don't explain what's wrong.

0

Also doesn't help perhaps explain why my version used to work but didn't, but I guess you might not know that

0

Eh seems to work though so nice job man, thanks. Dunno what was broke though

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.

2 comments

0

Interesting, I've already adopted the first answer, but I might change it a bit to be more like this one. Thanks.

0

I've tried your CFrame method on a different script, that works similar, and I do actually need to use CFrame now due to embedding it in the ground, but the problem is it also applies rotation to it which is a huge no-no.

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