Need help with tools

Hello everyone, I need help with a few of my tools on Roblox, I have made a key tool so that If you press “E” it is in your inventory. Now the scripts work fine, however, there is a problem that has been bugging me for a while.

Instead of my tool being on the ground, it floats for some reason, How can I make it so that the tool stays on the ground? (I have tried to anchor and it completely breaks the game when I do this, I have tried to weld it as well, but It does not work)

This is what it looks like Ingame

This is what it looks like in studio

image

Any idea on how I can fix this?

Here is the code


local RS = game:GetService("ReplicatedStorage")
local PlaySoundRE = RS:WaitForChild("PlaySoundRE")

local prompt = script.Parent:FindFirstChild("ProximityPrompt", true)
local highlight = script:WaitForChild("Highlight")

local tool = script.Parent
tool.CanBeDropped = false

local SoundID1 = "rbxassetid://9116173759"
local SoundID2 = "rbxassetid://9116171371"

local client = nil

local function PlaySound()
	PlaySoundRE:FireClient(client, SoundID1)
	PlaySoundRE:FireClient(client, SoundID2)
end

for i,v in pairs(tool:GetDescendants()) do
	local newH = highlight:Clone()
	newH.Parent = v
end

prompt.Triggered:Connect(function(player)
	client = player
	PlaySound()

	tool.Parent = player.Backpack
	for i,v in pairs(tool:GetDescendants()) do
		if v:IsA("Highlight") then
			v:Destroy()
		end
	end
	prompt:Destroy()

	for i,v in pairs(tool:GetDescendants()) do
		if v:IsA("BasePart") then
			v.Anchored = false
			v.CanCollide = false
		end
	end

	for i,v in pairs(tool:GetDescendants()) do
		if v.ClassName == "TouchTransmitter" then
			v:Destroy()
		end
	end
end)
1 Like

Place qWeld inside the anchored tool. It will automatically weld the anchored tool for you and unanchor it when done.

Here’s some code optimizations to work alongside qWeld:

--// Events //--
local PlaySoundRE =  game:GetService("ReplicatedStorage").PlaySoundRE

--// Tool //--
local tool = script.Parent
local handle = tool.Handle

local prompt = handle.ProximityPrompt

--// Add a highlight //--
local highlight = script.Highlight:Clone()
highlight.Parent = tool

local SoundID1 = "rbxassetid://9116173759"
local SoundID2 = "rbxassetid://9116171371"

local function PlaySound(player)
	PlaySoundRE:FireClient(player, SoundID1)
	PlaySoundRE:FireClient(player, SoundID2)
end

--// Remove touch transmitter //--
tool.CanBeDropped = false
handle:FindFirstChildWhichIsA("TouchTransmitter"):Destroy()

--// Prompt Trigger //--
prompt.Triggered:Connect(function(player)
	PlaySound(player)

	tool.Parent = player.Backpack
	
	--// Use a single [for i,v loop]
	for _,v in ipairs(tool:GetDescendants()) do --// Use ipairs() for micro-optimization
		if v:IsA("Highlight") or v:IsA("TouchTransmitter") then
			v:Destroy()
		elseif v:IsA("BasePart") then
			v.CanCollide = false
		end
	end

	prompt:Destroy()
end)

Workspace hierarchy used during testing:
image

Hope this helps! :slight_smile:

1 Like

Hello! Thanks for responding btw, I tried your solution and It worked! thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.