Hello!
I need some help with trying to make a model not visible to the LocalPlayer when their Level (or certain leaderstat) is a certain amount.
For example, when they touch the object, it disappears and they get 1 coin and it never respawns/shows for them, but it is still visible/shows for everyone else.
Anyone knows how to do this? Feel free to ask any questions.
Thanks.
1 Like
You can either set the transparency on Touch to 1 and destroy it on the client, or do the same thing from a serverScript and fire to the client. Let me know if you want some sample code.
1 Like
Please send a sample script, just so I can see what you mean and replicate it into my own script. Thanks.
Sure. I’m not 100% sure how your games layout is, however here is a quick example of detecting touches on the server, but making it invisible forever (or destroying it) on the client.
-- server script
local TouchPart = script.Parent -- under the assumption the script is a direct child of the part. If you have multiple TouchParts it may be a better idea to put this in ServerScriptService and use CollectionService or a Folder with :GetChildren() instead
local function onPlayerTouch(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
local plr = game.Players:FindFirstChild(hit.Parent.Name)
game.ReplicatedStorage.RE:FireClient(plr, TouchPart) -- this requires a remote event in replicated storage named "RE"
end
end
TouchPart.Touched:Connect(onPlayerTouch)
-- localscript, somewhere like startergui or another descendant of the player/char would work!
local function RemovePartLocal(TouchPart)
TouchPart:Destroy() -- Destroys it for the client this was fired for. If you want this to simply go invisible, set transparency to 1 and then turn CanCollie to false.
end
game.ReplicatedStorage.RE.OnClientEvent:Connect(RemovePartLocal)
You could also detect touches on the client as well, but you’d have to specify that hit.Parent == game.Players.LocalPlayer
1 Like