Hi! I’m making a script where, if you press left click, you throw an object. But the problem is, that when you activate it, it takes the properties and code from other scripts. It seems that it only fires when other peoples weapons are equipped.
If it’s hard to understand, I have an example:
Let’s say if 2 players are in the game. 2 players has weapons equipped. Then I’d throw my weapon but then it copies the other weapons properties and throws multiple and at different speeds.
LocalScript firing the remote event:
local tool = script.Parent
local plr = game.Players.LocalPlayer
local activate = false
tool.Activated:Connect(function()
if not activate then
activate = true
game.ReplicatedStorage.Throw:FireServer(plr)
print("fired to server")
task.wait()
activate = false
end
end)
ServerScript receiving the fired remote event:
local touched = false
local TS = game:GetService("TweenService")
local clicked = false
game.ReplicatedStorage.Throw.OnServerEvent:Connect(function(plr, mouseHit)
if not clicked then
clicked = true
local clone = plr.Character:FindFirstChildWhichIsA("Tool").Handle:Clone()
print("Cloned weapon")
clone.Hitbox.Touched:Connect(function(hit)
if not touched then
touched = true
clone.CanTouch = false
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= plr.Character and hit.Parent.Name ~= "Rope" and hit.Parent.Name ~= "Celestial Worm" then
--print(hit.Parent)
if hit.Parent.Humanoid.Health > 0 then
local target = hit.Parent
local joints = target:GetDescendants()
target.Humanoid.BreakJointsOnDeath = false
game.ReplicatedStorage.YeetGain:FireClient(plr)
local killed = false
target.Humanoid.Died:Connect(function(killed)
game.ReplicatedStorage.YeetGainDeath:FireClient(plr)
end)
print(target.HumanoidRootPart)
print(target.HumanoidRootPart)
clone.Impact:Play()
print(hit.Parent.Name.." was hit by "..script.Parent.Name)
--if not extraTouch then
-- extraTouch = true
target:FindFirstChild("Humanoid").Health -= 1
--wait(1)
--extraTouch = false
--end
print(target)
print(target.Humanoid.Health)
if hit.Parent.Humanoid.Health > 0 then
if target.Name ~= "Dummy3" then
target.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
target.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
target.Humanoid.AutoRotate = true
target.Humanoid.WalkSpeed = 26
target.Humanoid.JumpPower = 7.5
for _,joint2nd in pairs(joints) do
if joint2nd:isA("Motor6D") then
joint2nd.Enabled = true
end
end
for _, child in pairs(target:GetDescendants()) do
if child.Name == "Att0" or child.Name == "Att1" or child:IsA("BallSocketConstraint") then
child:Destroy()
end
end
end
end
end
end
end
end)
plr.Character:FindFirstChildWhichIsA("Tool").Handle.Woosh:Play()
clone.Transparency = 0
local tool = clone.Parent
clone.Parent = game.Workspace
clone.Anchored = true
clone.CanCollide = false
clone.Hitbox.CanCollide = false
clone.CanTouch = true
clone.Hitbox.CanTouch = true
print(clone.Parent)
-- clone.Position = script.Parent.Handle.Position
clone.CFrame = plr.Character.HumanoidRootPart.CFrame+plr.Character.HumanoidRootPart.CFrame.LookVector * 5
local Tween = TS:Create(clone,TweenInfo.new(2.5),{CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.LookVector * 20})
Tween:Play()
--print(mouseHit)
task.wait(0.5)
touched = false
plr.Character:FindFirstChildWhichIsA("Tool").Handle.Transparency = 0
clicked = false
wait(2)
clone:Destroy()
end
end)
--clone.Touched:Connect(function(hit)
--local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
--print(plr,"was hit by",script.Parent.Name)
--end)
Any help appreciated!