#Part won't change color unless script is within said part

1 messages · Page 1 of 1 (latest)

eternal bramble
#

The image I've attached is a portion of a local script located with StarterPlayerScripts. I'm trying to have the mousePart change colors based on the result of a raycast. However, I've found out that the part only changes color when there is a script placed within the part itself. I'm going to need a way to send data to the script that has the part as it's parent so it can change color as intended, but how would I go about this?

eternal bramble
#

But do you have any idea on how you'd solve this

#

Getting data from one local script into another

shadow quartz
#

part.BrickColor=color ?

eternal bramble
# shadow quartz part.BrickColor=color ?

I tried using "color = Brickcolor.new("Toothpaste") and "color = Brickcolor.new("Deep blue") but it doesn't change the part's color unless the script is within the part

eternal bramble
shadow quartz
eternal bramble
#

Well yes

#

But I'm wondering if just saying "color" doesn't or does require the ".new" like using Brickcolor and Color3 do

#

And then again, the thing is, using "Brickcolor.new("Name")" did work, but only when it was a local script inside of the part. If the local script is in StarterPlayerScripts, it can't get the requirement to know when to change the part's color.

eternal bramble
eternal bramble
# shrewd whale give me the script
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local userInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local mousePart = workspace:WaitForChild("MousePart")
local color = mousePart.BrickColor
local range = 50

local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {mousePart, char}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
-- Makes it so mousePart and the character don't collide with the raycast

local function render()
    local mouse2DPosition: Vector2 = userInputService:GetMouseLocation()
    local mouse3DRay: Ray = camera:ViewportPointToRay(mouse2DPosition.X, mouse2DPosition.Y, 1)
    raycastResult: RaycastResult = workspace:Raycast(mouse3DRay.Origin, mouse3DRay.Direction*range, raycastParams)
    local mouse3DPosition
    
    if raycastResult then
        print("raycast hit")
        print(raycastResult)
        color = BrickColor.new("Toothpaste")
        mouse3DPosition = raycastResult.Position + Vector3.new(0, mousePart.Size.Y*0.5, 0)
    else 
        color = BrickColor.new("Deep blue")
        mouse3DPosition = (mouse3DRay.Origin + mouse3DRay.Direction*range) + Vector3.new(0, mousePart.Size.Y*0.5, 0)
    end
    
    mousePart.Position = mouse3DPosition
end

runService.RenderStepped:Connect(render)```
#

(this script is located within StarterPlayerScripts)

eternal bramble
#

NEVERMIND

#

It worked

#

The issue how i referring to the mousepart