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

[FE] How would I replicate mouse.Hit.p to the server?

Asked by
Fatul 9
7 years ago
Edited 7 years ago

I'm rather new to FE, but not to scripting. I'm not quite sure how this would work since mouse is client-side only..

LOCALSCRIPT

player = game.Players.LocalPlayer
repeat wait(.1) until player.Character
character = player.Character
mouse = player:GetMouse() 

mouse.Button1Down:connect(function(hit)
    game.Workspace.Events.Shoot:FireServer()
    script.Parent.Parent.V3.Value = mouse.Hit.p
end)

SERVERSCRIPT

repeat wait(.1) until script.Parent.Parent.Parent.Name ~= "StarterPack"
player = game.Players:FindFirstChild(script.Parent.Parent.Parent.Parent.Name)
character = player.Character
--
center = player.Character.UpperTorso
Cooldowns = player.Backpack.Cooldowns
Limit = Cooldowns.Limit
Current = Cooldowns.Current

game.Workspace.Events.Shoot.OnServerEvent:connect(function()
    if Cooldowns.Levitation.Value == 0 then
        local make = Instance.new("Part")
        make.Anchored = true
        make.CanCollide = false
        make.Transparency = 1
        make.Parent = character
        make.CFrame = player.Backpack.Vector3.Value --Basically here
        make.Name = "Target"
        if character.Ammo.Shot:FindFirstChild("Bullet") then
            local bullets = character.Ammo.Shot:GetChildren()
            for i=1,#bullets do
                if character:FindFirstChild("Target") then
                    bullets[i].Propulsion.Target = character.Target
                    bullets[i].Propulsion.MaxThrust = 10000
                    bullets[i].Propulsion.TargetRadius = 25
                    bullets[i].Propulsion.ThrustD = 0
                    bullets[i].Anchored = false
                    bullets[i]:FindFirstChild("Force"):destroy()
                    bullets[i].Propulsion:Fire()
--                  local touched = script.Touched:Clone()
--                  touched.Parent = bullets[i]
--                  touched.Disabled = false

                    coroutine.resume(coroutine.create(function() 
                        bullets[i].Touched:connect(function(hit)                            
                        if hit.Name ~= workspace.Name then
                            if hit.Name ~= "Bullet" then
                                if hit.Name ~= "Explosion" then
                                    if hit.Name == "Target" then
                                        local Target = character:FindFirstChild("Target")
                                        --
                                        local smoke = Instance.new("Smoke")
                                        local explode= Instance.new("Explosion")
                                            smoke.Parent = character:FindFirstChild("Target")
                                            explode.Parent = character:FindFirstChild("Target")
                                            Target.Name = "Explosion"
                                        bullets[i]:Destroy()

                                        local val = 0

                                        for i=1,20 do
                                        val = val+0.05
                                            if smoke ~= nil then
                                                smoke.Opacity = 0.05*(val)
                                                smoke.Size = 3
                                                explode.BlastPressure = 5
                                                explode.BlastRadius = 5
                                                explode.DestroyJointRadiusPercent = 0


                                                if smoke.Opacity == 1 then
                                                    smoke:Destroy()
                                                end
                                            end
                                        end
                                        --
                                    else
                                        --  
                                        local Target = character:FindFirstChild("Target")
                                        --
                                        local smoke = Instance.new("Smoke")
                                        local explode= Instance.new("Explosion")
                                            smoke.Parent = hit
                                            explode.Parent = hit
                                            Target.Name = "Explosion"
                                        bullets[i]:Destroy()

                                        local val = 0

                                        for i=1,20 do
                                        val = val+0.05
                                            if smoke ~= nil then
                                            smoke.Opacity = 0.05*(val)
                                            smoke.Size = 3

                                                if smoke.Opacity == 1 then
                                                    smoke:Destroy()
                                                end
                                            end
                                        end 
                                    end
                                end
                            end
                        end     
                        end)
                    end))
                    Cooldowns.Levitation.Value = 3
                    Current.Value = Current.Value-1
                end
            end
        end
    end
end)
0
Alright, what lines exactly are these happening on? Why not just send the tuple argument of the Hit.p to the server through the RemoteEvent? M39a9am3R 3210 — 7y

1 answer

Log in to vote
0
Answered by
StoIid 364 Moderation Voter
7 years ago
Edited 7 years ago

Simple enough..

In your LocalScript you would just send over the mouse's position when you fire the event

mouse.Button1Down:connect(function()
    local pos = mouse.Hit.p
    Event:FireServer(pos)
end
--This will send the mouse's position over to the server
--The ServerScript will read it as (PlrWhoFiredTheEvent, MousePositionInVector3)

So in your server script you'd just need to add another tuple argument to get the position which would be..

Event.OnServerEvent:connect(function(plr, mousepos)
    print(plr.Name.. ' clicked in this location: '..mousepos)   
    --first argument 'plr' is the person who fired the event (which is the first argument of server events) and the rest can be anything, but in this case 'mousepos' is the location of the mouse when we fired the event. 
end)

I think you should practice passing arguments with RemoteEvents if you're still having trouble.

You can place as many arguments as needed..

0
I see, I just didn't know how to send something clientside to the server, but I think I understand it now. Fatul 9 — 7y
Ad

Answer this question