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

ClickDetector.CursorIcon changing in script, but not while in function, why?

Asked by 4 years ago

Hello. I made a script that changes the door handle clickdetector icon depending on if it is open or not.

prefix = "rbxassetid://"
openIcon = "6081347829"
closeIcon = "6081348044"
knockIcon = "6081347938"
chainIcon = "6081348125"
outerPlace = script.Parent.Parent.OuterKnob.OuterKnob.ClickDetector
innerPlace = script.Parent.Parent.InnerKnob.InnerKnob.ClickDetector
bodyPlace = script.Parent.Parent.DoorBody.ClickDetector
chainPlace = script.Parent.Parent.HalfLockAccept.ClickDetector

bodyPlace.CursorIcon = prefix..knockIcon
chainPlace.CursorIcon = prefix..chainIcon
outerPlace.CursorIcon = prefix..openIcon
innerPlace.CursorIcon = prefix..openIcon

function onDoorStateChange(value)
    if (value == true) then
        outerPlace.CursorIcon = prefix..closeIcon
        innerPlace.CursorIcon = prefix..closeIcon
    else
        outerPlace.CursorIcon = prefix..openIcon
        innerPlace.CursorIcon = prefix..openIcon
    end
end

script.Parent.stateChange.Event:Connect(onDoorStateChange)

The icon gets changed as soon as the server starts and as this script is ran, but when the event is fired and the function is ran, it doesn't change. The if statement works, I tested it in the debugger. Also in the watch window, the outerPlace.CursorIcon and innerPlace.CursorIcon variables change but these changes aren't reflected in the game. Does anyone have any idea why it doesn't change?

0
is it a local script? Harry_TheKing1 325 — 4y
0
No. vonotige 49 — 4y
0
Doing things on the client (ex: a mouse or anything thats on their screen) should be handled on a local script. kepiblop 124 — 4y
0
But, It's a clickdetector, it changes the mouse for all players. Plus localscripts run code only in a limited amount of places. That means I can't just put it into this model and it would work. vonotige 49 — 4y

Answer this question