Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a local part appear when tool is equipped?

I am trying to make a tool which, when equipped, creates a localpart (one only seen by the local player) and I am kind of stuck.

sp=script.Parent
equipped=false

function onEquipped(mouse)
equipped=true
local player = game.Players.LocalPlayer 
local character = player.Character
local bin = Instance.new("Message")
bin.Name = 'LocalBin'
bin.Parent = character
local platform = Instance.new("Part")
platform.CFrame = character.Torso.CFrame * CFrame.new(0, -3, 0)
platform.Anchored = true
platform.Size = Vector3.new(10, 1.2, 10)
platform.Parent = bin
end
	
function onUnequipped()
	equipped=false
	game.Players.LocalPlayer.Character.LocalBin:remove()
end

sp.Equipped:connect(onEquipped)
sp.Unequipped:connect(onUnequipped)

Thanks in advance!

2 answers

Fixed it for you:

sp=script.Parent
equipped=false
local Cam = Workspace.CurrentCamera

function onEquipped(mouse)
equipped=true
local player = game.Players.LocalPlayer 
local character = player.Character
local platform = Instance.new("Part")
platform.Name = "ThePart"
platform.CFrame = character.Torso.CFrame * CFrame.new(0, -3, 0)
platform.Anchored = true
platform.Size = Vector3.new(10, 1.2, 10)
platform.Parent = Cam
end

function onUnequipped()
    equipped=false
    Cam.ThePart:Destroy()
end

sp.Equipped:connect(onEquipped)
sp.Unequipped:connect(onUnequipped)

It will only be seen by the local player because anything put locally into CurrentCamera can only be seen by the client. A handy trick to know.

3 comments

0

Thanks for the reply, unfortunately, this didn't work.

0

Are you sure?

0

I can't see any errors with the bits I added in.

There was 23 lines. You might not have copied all of the code.

This discussion is preserved as it was. New answers, comments, and votes are closed.