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

How to destroy object locally?

Asked by 5 years ago

I’m sorry if my question is worded wrong, I think locally is the right term to use. How would you go about destroying an object when it is touched, but only for the player that touches it? It will still be there for other players until they touch it.

Thanks in advance so much

0
Destroy the part from a local script User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by
uhTeddy 101
5 years ago
Edited 5 years ago

I created this LocalScript

local part = game:GetService("Workspace"):WaitForChild("Part") -- change "Part" to the part name

part.Touched:Connect(function(touch)
    local player = game:GetService("Players"):GetPlayerFromCharacter(touch.Parent)
    if player ~= nil then
        if player == game:GetService("Players").LocalPlayer then
            part:Destroy()
        end
    end
end)

Also, place this localscript in StarterPack

Just Change the Part in the local part to your parts name and you should be fine.

0
Thanks a lot! Worked perfectly. Fatal_disco 5 — 5y
0
Well actually, I tested it online and it doesn't work. In the studio it worked though. Online my character just climbs on top of the object, it don't get destroyed or anything. Fatal_disco 5 — 5y
0
Cancel that. Got it working. My mistake, your code was perfect. Thanks again Fatal_disco 5 — 5y
0
No problem. If you could please just accept that answer it would be great! it gives us both REP points! uhTeddy 101 — 5y
Ad

Answer this question