Scripting Simple change color random (Difference between Client and Server scripts)


IS there a script allowing a model to change its base color when touched? I tried some tutorial on scripting but i could not make it work even Simple scripts. The Basic tutorial IS teaching ho to Rex a box Who rezzes other boxes Who change color. What about a tutorial with a simo le starting Point.? Also IS there a way to give materiale to somebody… I wanted to set up a treasure Hunt where People collects items as prof of completino this IS trivial to do in secondlife but apparently almost impossibile ti do in hf…


So… Now I checked the very simple script

//  changeColorOnClickDown.js
(function () {
    var clicked = false;
    this.clickDownOnEntity = function (entityID, mouseEvent) {
        if (clicked){
            Entities.editEntity(entityID, { color: { red: 0, green: 255, blue: 255} });
            clicked = false;
        } else {
            Entities.editEntity(entityID, { color: { red: 255, green: 255, blue: 0} });
            clicked = true;

This is working as a client script, but not if set as a server script.
What I’m missing here is to understand fully if this is exactly the same equivalent to lsl changeColor (which is running on the server) or not.
I tried with two avatars and while it was client script the first avatar touches the box and it changed color, and the second avatar did see the change, so this seems quite equivalent to have it as a server script.

If I understand correctly the client script is acting on the client and then if properties are changed these are broadcasted to the server and hence to all the other clients?

And why this cannot be a server script? This is because the server scripts cannot understand touch?

This is very confusing indeed. Is there some tutorials explaining this difference somewhere in the web?

Looking in the docs the only thing I find is the following:
Client script

When you attach a client script to an entity, the entity responds to a trigger or event. For instance, you can attach a script to an entity that changes the entity’s color when a user clicks on it.

Server script

Scripts that are attached to entities and run in the Entity Server are called Server Entity scripts.

So what are the difference between them? Why there is not an example in the doc explaining it and stating the real difference? Is it correct what I can infere that only a limited set of triggers can be handled by the server scripts and this is not including the touch?

There is an example however in the server script teaching how to flicker tea lights. I’m a bit confused why this is done as a server script, wouldn’t it be better done in the client? Which is the benefit in launching it on the server? Which would be the equivalent if we wanted it to be client side? Is there a syntax function difference in that case? A looot of questions and the documentation seems not helping so much …


Now there is something here where there is some description of the differences, but it surely needs some examples to be added to help people in really understand the different types of scripts. Also the API documentation provided is frankly almost empty.
For instance look at the following:

getAvatar(avatarID) → {AvatarData}
Name Type Description
avatarID Uuid
Type: AvatarData

I dont have any clue on what is the definition of avatardata…


Client script is running only on your interface. You can make it do what your user is allowed to do. It can change the property of an entity (EditEntity) which will be immediately visible to other. But if another user run the script, and don’t have permission to edit (it won’t work for that user).

Sever script is urn by the server, at your name. As it’s the server that is running it, the results will be reflected to other. But here too, it’s going to be limited to your permission level.
(It’s probably ignorant of what action you did. Outside triggering the script)

In the 2 case, if you lock the entity, It’s not going to allow to let you visitor change the color (except if you grant the permission to all, which is not a big deal)

I agree the doc is deficient, it’s still very beta.
(it’s even more difficult to find our path in it than it was one year ago)
I’ve found many answer by checking directly in the code (on GitHub) there is also many good example in the script archive, giving good clue if it’s not alway fully up to date.

I’m not sure but I think I read somewhere that dev are now documenting the new stuff and what the have to revisit as the are coding. (If it’s not the case, maybe it would be a good way to solve that problem gradually.)


Thanks @Alezia.Kurdis for the insights. There are still something unclear, I really want to grasp the scripting, but sofar it seems 100 times harder to even start than lsl (which was the ugliest language I ever saw).
HF scripting seems very very powerful and very very interesting.
What I think it is really really needed is a kind of addon for visual studio code or for eclipse or for intellij, allowing people to autocomplete, find the methods and documentation in an easier way. Now everything seems burdened under feets of debris and obfuscations :slight_smile:
I’ve seen that someone did do a great job in trying to do the tutorial which is not bad, but the language itself is so complex and powerful that a REAL manual is needed. I also have seen that some scripts are even signed directly from @philiprosedale so it seems that he is a real scripter / programmer after all, I hope he is willing to have scripters using this API in the best way possible. In SecondLife and OpenSim scripts were VERY important to enhance the interactivity. I suspect that they are equally important in HF.
Are there any videos explainin how to code in HF?


Now this is very curious. I tried the following client script, which is rapidly changing color of a cube when clicking and remove the timer when clicked again so stop the flickering. What happens is that if 1st avatar clicks, then both are seeing the flickering cube, while only the first who clicked can stop the timer clicking again.
What I cannot understand is if the second client is still called and tries to change the colors but it is shadowed by the first script of if it is really disabled since the first script is running on the entity.

Can somebody explain me what is really happening in such a case?

// changeColorOnClickDown.js
(function () {

function rndByte() {
return (Math.floor(Math.random() * Math.floor(255))).toString();
var enabled = false;
var timer;

this.clickDownOnEntity = function (entityID, mouseEvent) {
if(enabled) {
enabled = false;
} else {
enabled = true;
entity = entityID;
timer = Script.setInterval(function() {
{ color: { red: rndByte(), green: rndByte(), blue: rndByte()} }




You have to remember, server scripts have no interactions because the client has to have access to the function to call it (via clicks or interactions)

I made a partial post About it at

Specifically look up the Types of Scripts where I discuss that Entity Server Scripts can be though of being so that “They” are in control.

If you want to hide something behind the server script or assignment client, you first have to have an entity script that a client can interface with, which can send a message to the entity server script.

The difference here is the fact that the entity server script has full permissions on the server as it is run by the server it self (Think of it as an Entity script, but only run by the server). This means you can lock and unlock entities and do things that a normal guests to the domain cannot do. (which is why setting scripts group and entity edit filters is important, but not so often discussed.

You do have to remember that the entity server script is centralized, and can behave as a controller.


Interesting I will read your post very carefully, hope to find a way to synchronize client scripts with server scripts as you are suggesting :slight_smile:

This makes a lot of sense in reducing lag, so it is definitely superior to LSL in secondlife, but unluckily I didn’t find any documentation or tutorials, yet… Need to be Indiana Jones to hunt for all the hings and treasure hunts in this forums…


I’d have to look it up, but you can do just that. Effectively, given you have let the script allow it, you can execute server script functions from the client. You would be running two scripts:

  1. Client script that sends commands to the server script on your behalf
  2. Server script that performs the actions

This would meaning writing extra things, but you can also view it this way: you can effectively lock down certain things as well.

Say, for example, we took that script further: an IFTTT (If This Then That) function to change an LED light in the real world. It’s okay to expose a click script to the client but we would want to keep the server the contain knowledge on the passcode needed for IFTTT to operate the LEDs (and anything else). The client script is run on the client, with the client having to have a copy in memory to figure it out. The server, on the flipside, has its own script that it runs that the client doesn’t have access to, which also contains our passkey.

The end result? Security and desired effects.

In essence, the same could be said for the original topic: unless I’m not mistaken, the server has natural full permissions to do actions to itself, so if you wanted to have an object that changed colors, under normal conditions, we are assuming the user has edit rights (which they may not). By having a server script enact changes on the object on our behalf, we don’t have to expose edit rights to the user to perform the change.


Just as a side note, if you edit a locked object you must first unlock it before you can send an edit query, doing what you want with it and locking it again. You have to send two edits :slight_smile: