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

So basically I only have errors when I add script.parent.Mousebutton1click can someone help?

Asked by 3 years ago

whenever I add this script.Parent.MouseButton1Click:Connect(function to a button fro a script I always get a error

script.Parent.MouseButton1Click:Connect(function local plr = game.Players.LocalPlayer local mouse = plr:GetMouse()

localplayer = plr

if workspace:FindFirstChild("Core") then workspace.Core:Destroy() end

local Core = Instance.new("Part") Core.Name = "Core" Core.Size = Vector3.new(0.05, 0.05, 0.05)

spawn(function() Core.Parent = workspace local Weld = Instance.new("Weld", Core) Weld.Part0 = Core Weld.Part1 = localplayer.Character.LowerTorso Weld.C0 = CFrame.new(0, 0, 0) end)

workspace:WaitForChild("Core")

local torso = workspace.Core flying = true local speed=10 local keys={a=false,d=false,w=false,s=false} local e1 local e2 local function start() local pos = Instance.new("BodyPosition",torso) local gyro = Instance.new("BodyGyro",torso) pos.Name="EPIXPOS" pos.maxForce = Vector3.new(math.huge, math.huge, math.huge) pos.position = torso.Position gyro.maxTorque = Vector3.new(9e9, 9e9, 9e9) gyro.cframe = torso.CFrame repeat wait() localplayer.Character.Humanoid.PlatformStand=true local new=gyro.cframe - gyro.cframe.p + pos.position if not keys.w and not keys.s and not keys.a and not keys.d then speed=5 end if keys.w then new = new + workspace.CurrentCamera.CoordinateFrame.lookVector * speed speed=speed+0 end if keys.s then new = new - workspace.CurrentCamera.CoordinateFrame.lookVector * speed speed=speed+0 end if keys.d then new = new * CFrame.new(speed,0,0) speed=speed+0 end if keys.a then new = new * CFrame.new(-speed,0,0) speed=speed+0 end if speed>10 then speed=5 end pos.position=new.p if keys.w then gyro.cframe = workspace.CurrentCamera.CoordinateFrameCFrame.Angles(-math.rad(speed0),0,0) elseif keys.s then gyro.cframe = workspace.CurrentCamera.CoordinateFrameCFrame.Angles(math.rad(speed0),0,0) else gyro.cframe = workspace.CurrentCamera.CoordinateFrame end until flying == false if gyro then gyro:Destroy() end if pos then pos:Destroy() end flying=false localplayer.Character.Humanoid.PlatformStand=false speed=10 end e1=mouse.KeyDown:connect(function(key) if not torso or not torso.Parent then flying=false e1:disconnect() e2:disconnect() return end if key=="w" then keys.w=true elseif key=="s" then keys.s=true elseif key=="a" then keys.a=true elseif key=="d" then keys.d=true elseif key=="x" then if flying==true then flying=false else flying=true start() end end end) e2=mouse.KeyUp:connect(function(key) if key=="w" then keys.w=false elseif key=="s" then keys.s=false elseif key=="a" then keys.a=false elseif key=="d" then keys.d=false end end) start()

0
and it's whenever i add it to a script like that one TurkishBTW 2 — 3y
2
can you use the code block? Because my eyes are suffering rn. 1JBird1 64 — 3y
0
same kidsteve923 139 — 3y
0
Please use the code block (or press the lua button when you writing the question), so that people (including me) will have it much easier to understand your script. Buzzettego 5 — 3y
0
how do I use a code block? TurkishBTW 2 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
script.Parent.MouseButton1Click:Connect(function()
    local plr = game.Players.LocalPlayer
    local mouse = plr:GetMouse()

    local player = plr

    if workspace:FindFirstChild("Core") then workspace.Core:Destroy() end

    local Core = Instance.new("Part") Core.Name = "Core" Core.Size = Vector3.new(0.05, 0.05, 0.05)

    spawn(function() Core.Parent = workspace local Weld = Instance.new("Weld", Core) Weld.Part0 = Core Weld.Part1 = localplayer.Character.LowerTorso Weld.C0 = CFrame.new(0, 0, 0) end)

    workspace:WaitForChild("Core")

    local torso = workspace.Core 
    flying = true 
    local speed=10
    local keys={a=false,d=false,w=false,s=false}
    local e1
    local e2 
    local function start()
        local pos = Instance.new("BodyPosition",torso)
        local gyro = Instance.new("BodyGyro",torso)
        pos.Name="EPIXPOS"
        pos.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        pos.position = torso.Position
        gyro.maxTorque = Vector3.new(9e9, 9e9, 9e9)
        gyro.cframe = torso.CFrame
        repeat wait()
            player.Character.Humanoid.PlatformStand=true 
            local new=gyro.cframe - gyro.cframe.p + pos.position 
            if not keys.w and not keys.s and not keys.a and not keys.d then
                speed=5
            end
            if keys.w then 
                new = new + workspace.CurrentCamera.CoordinateFrame.lookVector * speed 
                speed=speed+0
            end 
            if keys.s then 
                new = new - workspace.CurrentCamera.CoordinateFrame.lookVector * speed 
                speed=speed+0
            end 
            if keys.d then 
                new = new * CFrame.new(speed,0,0) 
                speed=speed+0
            end 
            if keys.a then 
                new = new * CFrame.new(-speed,0,0)
                speed=speed+0
            end
            if speed>10 then
                speed=5 
            end
            pos.position=new.p 
            if keys.w then 
                gyro.cframe = workspace.CurrentCamera.CoordinateFrameCFrame.Angles(-math.rad(speed0),0,0)
            elseif keys.s then
                gyro.cframe = workspace.CurrentCamera.CoordinateFrameCFrame.Angles(math.rad(speed0),0,0)
            else
                gyro.cframe = workspace.CurrentCamera.CoordinateFrame 
            end 
        until flying == false 
        if gyro then 
            gyro:Destroy()
        end 
        if pos then
            pos:Destroy()
        end 
        flying=false 
        player.Character.Humanoid.PlatformStand=false
        speed=10 
    end
    e1=mouse.KeyDown:connect(function(key) 
        if not torso or not torso.Parent then 
            flying=false
            e1:disconnect()
            e2:disconnect()
            return
        end
        if key=="w" then 
            keys.w=true
        elseif key=="s" then 
            keys.s=true 
        elseif key=="a" then 
            keys.a=true
        elseif key=="d" then 
            keys.d=true 
        elseif key=="x" then 
            if flying==true then
                flying=false 
            else 
                flying=true
                start()
            end
        end 
    end)
    e2=mouse.KeyUp:connect(function(key)
        if key=="w" then
            keys.w=false 
        elseif key=="s" then 
            keys.s=false 
        elseif key=="a" then
            keys.a=false
        elseif 
            key=="d"
        then 
            keys.d=false 
        end 
    end) 
    start()
end)

does this help you? you forgot an "end)" at the end of the code to close the mousebutton1click function also use code block and use the enter key for posting here, many people aren't used to just using 1 line to write a full code, and it's better to use the enter key so its easier to organize and the computer is happy when checking the code.

0
thx for helping but now the fly script wont work TurkishBTW 2 — 3y
0
oh fullguyblox3 69 — 3y
Ad

Answer this question