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

How do I change the properties of a part for only one player?

Asked by
Sulu710 142
5 years ago

So I'm trying to create a part where once you get in a certain radius of it, it will be outlined using a SelectionBox. This works perfectly fine, except when one player goes in the specified radius of the part, the part gets outlined for every player instead of just that one player. I'm doing this using a local script inside the PlayerGui that changes the transparency of the SelectionBox when you get close enough, so shouldn't it only happen for the LocalPlayer if I'm using a local script? This is what I have inside my local script in the player gui:

Task1Part = workspace:WaitForChild("Task1Part") -- The part to get outlined
Task1Trigger = Task1Part:WaitForChild("Task1Trigger") -- The invisible part that detects when a player gets near enough to the part
SelectionBox = Task1Part:WaitForChild("SelectionBox") -- The selection box whose "Adornee" property is set to the Task1Part

Task1Trigger.Touched:Connect(function(Toucher)
    if Toucher.Parent.Humanoid and Toucher.Name == "HumanoidRootPart" then
        SelectionBox.Transparency = 0
    end
end)

Task1Trigger.TouchEnded:Connect(function(Toucher)
    if Toucher.Parent.Humanoid and Toucher.Name == "HumanoidRootPart" then
        SelectionBox.Transparency = 1
    end
end)

So basically what I want to know is, how do you change the properties of an instance in the workspace for only one player? I have filtering enabled on and experimental mode off, and I can't figure it out, so any help would be highly appreciated. Thank you for reading!

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

If the filtering enabled is actived normally you can't view the changement with the server so other player doesn't view this changement. If I can you propose a other script to a maximum of optimisation.

local PlayerService = game:GetService('Players')
local Player = PlayerService.LocalPlayer -- To found the player

local Range = 15 -- Distance

local Task1Part = workspace:WaitForChild("Task1Part")
--local Task1Trigger = Task1Part:WaitForChild("Task1Trigger") -- You can remove it, it's no longer useful now:)
local SelectionBox = Task1Part:WaitForChild("SelectionBox")

while wait() do
    if Player.Character and (Player.Character.HumanoidRootPart.Position - Task1Part.Position).magnitude < Range then
        SelectionBox.Transparency = 0
    else
        SelectionBox.Transparency = 1
    end
end

What's magnitude?

Make sure the SelectionBox are origin in the Studio transparent and that code is on a LocalScript! To more question ask below

0
This worked well, thank you much! I'm still curious though, what made your script show show the selection box for only one player and mine showed for all of them? Sulu710 142 — 4y
0
Oh never mind I figured it out. When any player touched the trigger, the local script ran because I only specified that it must be a character that touches the trigger, not the necessarily the local player's character. Sulu710 142 — 4y
Ad

Answer this question