So I'm making another gun script and for it to work, it passes over some of the tools parts to a server script and stuff. Well I am trying to get the position of the handle's children but when it passes over the handle, the children aren't passed with it. I just need a way to get access to the children when they get passed over so I can get its position. I've tried searching it up and stuff but I can't find what I need
#Little issue
24 messages · Page 1 of 1 (latest)
local mouse = player:GetMouse()
local Tool = script.Parent
local cooldown = false
local cooldownTime = 0.1
local function Pew()
Tool.Handle.PointLight.Enabled = true
local pew = Tool.Handle.pew
pew:Play()
game.ReplicatedStorage.DuckShoot:FireServer(mouse.Hit.p, Tool.Handle)
end
local function Shoot()
-- Function code
if cooldown == true then
return
end
cooldown = true
Pew()
print("Firing")
wait(cooldownTime)
cooldown = false
Tool.Handle.PointLight.Enabled = false
end
Tool.Activated:Connect(function()
-- Will run when player clicks with weapon equipped
Shoot()
end)```
Tool.Handle.PointLight.Enabled = true
local pew = Tool.Handle.pew
pew:Play()
game.ReplicatedStorage.DuckShoot:FireServer(mouse.Hit.p, Tool.Handle)
end```
This is where it passes over the stuff to the serverscript
but when it passes over the handle it doesnt pass over the children
In the serverscript
local range = 500
local duckgun = game.StarterPack.DuckGun1
game.ReplicatedStorage.DuckShoot.OnServerEvent:Connect(function(Player, TargetLocation, Handle)
if Player.Character == nil then -- Make sure the character exists
return
end```
This is where I need to get it into
game.ReplicatedStorage.DuckShoot.OnServerEvent:Connect(function(Player, TargetLocation, Handle)
I need it to also include the children but everytime i've done it, it fails
One thing I tried was to add Local Children = Tool.Handle:GetChildren() and then pass that over but it didn't work
I've also tried just getting the part I need and passing that over
but when I go to do the position
It gives the old position rather then where it is now which is in the player's inventory
Actually I found that when I got the descendants of it and prinetd all the descendants, it did pass over the stuff but somehow can't find the new position of the part I want
So basically I found that my issue is that in the rayOrigin part of my script, it can't find the part of the handle from the tool im holding. It only can find the old location
local range = 500
local duckgun = game.StarterPack.DuckGun1
game.ReplicatedStorage.DuckShoot.OnServerEvent:Connect(function(Player, TargetLocation, Handle)
if Player.Character == nil then -- Make sure the character exists
return
end
local rayOrigin = Handle.CFrame.p
local rayDirection = (TargetLocation - Handle.CFrame.p).unit * 300
local raycastparams = RaycastParams.new()
raycastparams.FilterDescendantsInstances = {Player.Character}
raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
local result = workspace:Raycast(rayOrigin, rayDirection, raycastparams)
local laser1 = Instance.new("Part", workspace)
laser1.Name = "Laser1"
laser1.Position = rayOrigin
local distance = (rayOrigin - TargetLocation).Magnitude
laser1.CFrame = CFrame.new(rayOrigin, TargetLocation) * CFrame.new(0, 0, -distance/2)
laser1.Anchored = true
laser1.CanCollide = false
-- Make the color of the laser cyan with color3
laser1.Color = Color3.new(0, 1, 1)
laser1.Material = Enum.Material.Neon
laser1.Size = Vector3.new(0.1,0.1,distance)```
local rayOrigin = Handle.CFrame.p
With this part
it shoots from the handle
but when I make it to the lefteye
it doesn't do it
it gets the old position of it