简体   繁体   中英

Roblox Player Part properties

I'm new to Roblox development. This is a pretty simple question. Googling this is hard to find anything.

Is there a way to make the a single part have different properties to depending on player attributes/events?

Example: Setup: Two Players and one part. The part is a blue brick.

Scenario: Let's say one player touches a part and it changes red. Is there anyway for that part to only to appear red to the player who touched it? Allowing the other player to still see the blue part unchanged?

Yes - you'll want to make the changes happen locally on the client that you want the change to happen via a LocalScript. Consider a part in the workspace (workspace.Part) and a LocalScript in StarterCharacterScripts:

local character = script.Parent
local part = workspace.Part

local function onPartTouched(touchingPart)
    if touchingPart.Parent == character then
        part.Color = Color3.fromRGB(255, 0, 0)
    end
end

part.Touched:Connect(onPartTouched)

Meanwhile you can still have a Touched event lister in a server-side script as well to perform other actions with that player on the server. Having a client-side listener and a server-side listener are not mutually exclusive.

Also know that if the server ever makes any changes to that part afterwards, for example set the color of the part to Yellow, that change will replicate to all clients regardless if they were currently Red or Blue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM