Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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.

0
Thanks for the reply, unfortunately, this didn't work. Mkoalko 0 — 10y
0
Are you sure? Archonious2 160 — 10y
0
I can't see any errors with the bits I added in. Archonious2 160 — 10y
Ad
Log in to vote
0
Answered by 8 years ago

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

Answer this question