Desired alpha is not working

Hello there, How are we?

I am working on a game mode, and I have a slight problem, I am aiming to make it so if they are in the team “Ghost” Then the alpha of the player model changes depending on there speed, for example.

If they are sprinting, there speed is 255, so they will be completely visible.
If they are walking, there speed is 175, so they will be partially visible.
If they are are stood still, there speed will be 0, so they will be invisible.
etc. etc.

In the code you will see how I am attempting to achieve this, currently I am getting their velocity and setting it to a vector so it becomes 1 number (instead of 3) and then using that to determine there alpha. However whilst testing this, it is not working. If anyone knew how to or knows where I am going wrong, that would be perfect.

Also 1 more thing, I have on GM:PlayerInitialSpawn( ply ), Trying to set them to team 3, and set them to spectate, but that doesnt work either and the player model is that werid non existing black playermodel you get if you play half life and go into third person.

[lua]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( “shared.lua” )
include( “player.lua” )

– Beautiful thing about local functions is that it can only be accessed from this file.

function GM:PlayerConnect( name, ip )
print( "Player : " … name … “, has joined the game.” )
end

function GM:PlayerInitialSpawn( ply ) – player entity
ply:SetTeam( 3 )
ply:StripWeapons()
ply:Spectate( 3, OBS_MODE_FIXED)
end

function GM:PlayerAuthed( ply, steamID, uniqueID )

end

function GM:Move( ply, movedata )
if team.GetName( ply:Team() ) == “Ghost” then
ply:SetModel( “models/player/odessa.mdl” )
local NewAlpha = math.Round( Vector( 0, 0, 0 ):Distance( movedata:GetVelocity() ) )
print( Vector( 0, 0, 0 ):Distance( movedata:GetVelocity() ) )
ply:SetColor( Color(255, 255, 255, NewAlpha) )
end
end

function GM:PlayerSpawn( ply )
if team.GetName( ply:Team() ) == “Ghost” then
ply:SetRunSpeed( 255 )
ply:SetWalkSpeed( 175 )
ply:Give( “weapon_crowbar” )
–ply:SetModel( “models/player/Charple01.mdl” )
end
if team.GetName( ply:Team() ) == “Hunter” then
ply:SetRunSpeed( 255 )
ply:SetWalkSpeed( 175 )
ply:Give( “weapon_357” )
ply:Give( “weapon_crowbar” )
–ply:SetModel( “models/player/Police.mdl” )
end
end

function GM:PlayerSetModel( ply )
ply:SetModel( “models/player/odessa.mdl” )
end

function ChangeMyTeam( ply, cmd, args )
ply:SetTeam( args[1] )
ply:Spawn()
end
concommand.Add( “set_team” , ChangeMyTeam )
[/lua]

Thank you to anyone who reads or posts in this thread.

ply:SetRenderMode( RENDERMODE_TRANSALPHA ) ?

Hi there, thanks a lot that has worked!