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

How can i turn a part spawned by a local script to a server sided part?

Asked by 3 years ago

I made a script that spawns a lazerbeam going to the place of where your mouse is located but since its from a local script other players can't see it. how can i make the part into a server sided part?

(sorry if this is a dumb question im kinda new to scripting)

script:

local Debris = game:GetService("Debris")

local LaserGun = script.Parent

local playerName = script.Parent.Parent.Name
local Player = game.Workspace:FindFirstChild(playerName)

local cooldownQ = 10



local Character = Player.Character

local GunDamage = 0
local shots = 0

LaserGun.Equipped:Connect(function(Mouse)
    Mouse.Button1Down:Connect(function()

        if os.time() - Player.cooldownQ.Value > cooldownQ then  
            wait(2)

        local Tip = script.Parent.Tip
        local Laser = Ray.new(Tip.CFrame.p, (Mouse.Hit.p - Tip.CFrame.p).unit * 300)
        local HitPart, HitPosition = game.Workspace:FindPartOnRay(Laser, Character, false, true)


        local dmgscript = game.ReplicatedStorage.LazerBeam.dmg
        local cloneddmgscript = dmgscript:Clone()   
        local LaserBeam = Instance.new("Part", game.Workspace)
        LaserBeam.BrickColor = BrickColor.new("Bright red")
        LaserBeam.FormFactor = "Custom"
        LaserBeam.Material = "Neon"
        LaserBeam.Transparency = 0.25
        LaserBeam.Anchored = true
        LaserBeam.CanCollide = false
        LaserBeam.Name = "LaserBullet"
        cloneddmgscript.Parent = game.Workspace.LaserBullet

        local LaserDistance = (Tip.CFrame.p - HitPosition).Magnitude
        LaserBeam.Size = Vector3.new(2, 2, LaserDistance)
        LaserBeam.CFrame = CFrame.new(Tip.CFrame.p, HitPosition) * CFrame.new(0, 0, -LaserDistance/2)

            Debris:AddItem(LaserBeam, 2)                

        if HitPart then
            local HitHumanoid = HitPart.Parent:FindFirstChild("Humanoid")

            if not HitHumanoid then
                HitHumanoid = HitPart.Parent.Parent:FindFirstChild("Humanoid")
                wait(2)
                end

            if HitHumanoid then
                HitHumanoid:TakeDamage(GunDamage)
            end
        end
    end
end
    )
end)

0
Look up remote events, if you trigger a remote event from the client, the server can detect it. you can even use args, but make sure you make all of the "checks" server sided, so basically make sure people can't just fire the event in your game, since any client can fire a remote event if they have exploits DarkCaveSpider 25 — 3y
0
i. e. Spawn it on the server, just get the event from the client. DarkCaveSpider 25 — 3y
0
alr i got it ty lolletjes123 5 — 3y

Answer this question