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

Flag placing script won't work?

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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)
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. Maxwell_Edison 105 — 9y
0
Also doesn't help perhaps explain why my version used to work but didn't, but I guess you might not know that Maxwell_Edison 105 — 9y
0
Eh seems to work though so nice job man, thanks. Dunno what was broke though Maxwell_Edison 105 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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.

0
Interesting, I've already adopted the first answer, but I might change it a bit to be more like this one. Thanks. Maxwell_Edison 105 — 9y
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. Maxwell_Edison 105 — 9y

Answer this question