Weird physics simulation (Yes, scripting related)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    i want to make a very simple throwing system
  2. What is the issue? Include screenshots / videos if possible!
    the throwing’s physics only simulate when getting close
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local player = Players.LocalPlayer
local heldPart = nil

for i, part in ipairs(workspace:GetDescendants()) do
	if part:IsA("BasePart") and part:HasTag("X") then
		local prompt = Instance.new("ProximityPrompt", part)
		prompt.Triggered:Connect(function()
			if heldPart then return end
			
			prompt.Enabled = false
			heldPart = part
			local character = player.Character or player.CharacterAdded:Wait()
			local weld = Instance.new("WeldConstraint", part)
			weld.Part0 = character:WaitForChild("HoldPos")
			weld.Part1 = part
		end)
	end
end

workspace.ChildAdded:Connect(function(part)
	if part:IsA("BasePart") and part:HasTag("X") then
		local prompt = Instance.new("ProximityPrompt", part)
		prompt.Triggered:Connect(function()
			if heldPart then return end
			
			prompt.Enabled = false
			heldPart = part
			local character = player.Character or player.CharacterAdded:Wait()
			part.CFrame = character:WaitForChild("HoldPos").CFrame
			local weld = Instance.new("WeldConstraint", part)
			weld.Part0 = character:WaitForChild("HoldPos")
			weld.Part1 = part
		end)
	end
end)

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q and heldPart then
		
		heldPart:WaitForChild("WeldConstraint"):Destroy()
		local attachment = Instance.new("Attachment", heldPart)
		heldPart.Anchored = false
		
		heldPart:ApplyImpulse(player.Character.Head.CFrame.LookVector * 80)

		heldPart:FindFirstChild("ProximityPrompt").Enabled = true
		heldPart = nil
		
	end
end)

its a local script located in starterplayerscripts

I don’t know the full context of the game, or the functionality and how far you can throw something, but if the issue is its not working unless you’re close, thats due to the clients rendering and streaming enabled. if something is too far,. the client won’t render it in the workspace and therefore it won’t “exist” in the workspace for the client unless a previous reference is attached to it. so you should switch your streaming enabled if you want all the chunks to be constantly rendered and throwing to work

1 Like

Im not sure if i understand the problem right but it sounds like network ownership…
Could you share a video so we can better understand your issue?

Also I highly suggest using CollectionService:GetInstanceAddedSignal instead of .ChildAdded. You should also consider using a function that gets called in the AddedSignal and in the Loop, because code duplication is not good and can be easily prevented!

1 Like