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

How to make a part dissapear for ONLY the player touching it?

Asked by 3 years ago

I am trying to make a GUI pop up after touching a part, the part will then be removed after being touched. The problem is that the part removes for all players after being touched by only one. How would I make this part only remove for the person touching it?

0
Copy the code into a local script, and make it work on the local side iiii676 23 — 3y

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
3 years ago
Edited 3 years ago

Use a LocalScript, that way it only works for one client.

local Part = nil -- change to part location
local Players = game:GetService('Players')

local UI = nil -- change this to UI location

function onTouched(Hit)
    local Player = Players:GetPlayerFromCharacter(Hit.Parent)
    if Player then
        local newUI = UI:Clone()
        newUI.Parent = Player.PlayerGui
        Part:Destroy()
    end
end)

part.Touched:Connect(onTouched)
0
This did not remove the part, I put the local script inside of the part. Should I put it somewhere else? mcbeavers 0 — 3y
0
You should put in StarterGui, ReplicatedFirst or [StarterCharacter/Player]Scripts. pwx 1581 — 3y
Ad

Answer this question