-
What do you want to achieve? Keep it simple and clear!
Anchors the weapon when touches the floor -
What is the issue? Include screenshots / videos if possible!
it although the weapon has the same script, the weapon don’t stay in the same position as others
-
What solutions have you tried so far?
I added a part to see the goal of the ray cast and try to check the error
Here is the script for raycasting:
local part = script.Parent
local test = Instance.new("Part",part)
test.CFrame = part.CFrame + script.Parent.CFrame.UpVector * 10
test.CanCollide = false
test.Massless = true
test.Anchored = false
local weld = Instance.new("WeldConstraint",part)
weld.Part0 = part
weld.Part1 = test
while true do
local distance = 10
wait(0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001)
local para = RaycastParams.new()
para.FilterType = Enum.RaycastFilterType.Whitelist
para.FilterDescendantsInstances = game.Workspace.obj:GetChildren()
local result = workspace:Raycast(script.Parent.Position,script.Parent.CFrame.UpVector * distance ,para)
if result then
part.Anchored = true
script.Disabled = true
end
end
And here’s the script for spawning the weapon(This is a single player game so I used FindFirstChildOfClass for getting the player):
local Players = game:GetService("Players")
local ts = game:GetService("TweenService")
while true do
wait()
local player
while player == nil do
player = game.Players:FindFirstChildOfClass("Player")
wait()
end
local char = game.Workspace:WaitForChild(player.Name)
if char then
local charpos = char:WaitForChild("HumanoidRootPart",1000000).Position
local charcf = CFrame.lookAt(script.Parent.HumanoidRootPart.Position,charpos)
local goal = {
['CFrame'] = charcf
}
local tsinfo = TweenInfo.new(
0.2
)
local tween = ts:Create(script.Parent.HumanoidRootPart,tsinfo,goal)
tween:Play()
local hum = script.Parent.Humanoid
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=7535246528"
local animationTrack = hum:LoadAnimation(animation)
animationTrack:Play()
local rs = game.ReplicatedStorage
local tri = rs.Trident:Clone()
tri.Parent = game.Workspace
tri.CFrame = script.Parent.RightHand.CFrame * CFrame.Angles(math.rad(-90),0,0)
local goal = {
Transparency = 0
}
local tsinfo = TweenInfo.new(
1
)
local tween = ts:Create(tri,tsinfo,goal)
tween:Play()
local weld = Instance.new("WeldConstraint",tri)
weld.Part0 = tri
weld.Part1 = script.Parent.RightHand
wait(120/60)
tri.BodyGyro.CFrame = charcf * CFrame.Angles(math.rad(-90),0,0)
local bv = Instance.new("BodyVelocity",tri)
bv.Velocity = charpos - tri.Position
bv.P = 3000
tri.RayCast.Disabled = false
tween:Play()
weld:Destroy()
wait(50/60)
end
end