um:ReadString() help

Hey im working on a petrol script its working epicly apart form i cant pass the petrol value to the client
im using user messages

print(“Petrol: “…(um:ReadString())…”%”)

its just says its 0 even tho ive done

SendData2(“petrolUpdate”, ply, petrol)

Any ideas or help would much appreciated

Can you show the whole code (or at least the functions with the hooks )?
And the second line you have posted isn’t related to sending usermessages…

function SendData2(func, ply, petrol)
umsg.Start(func, ply)
umsg.String(petrol)
umsg.Long(petrol)
umsg.End()
end

function petrol(um)
petrol = um:ReadString()
end

usermessage.Hook(“petrol”, petrol)

[editline]09:41PM[/editline]

is there a simpler way to share a Variable between server and client?

[lua]if ( SERVER ) then

function GM:KeyPress( pl, key )

	-- When the player jumps
	if ( pl:Alive( ) and key == IN_JUMP ) then
	
		-- Reduce his petrol
		pl.Petrol = pl.Petrol - 1
	
		-- And send it to the client:
		-- pl.Petrol is a server-side INTEGER, and can be sent as one.
		umsg.Start( "playerpetrol" )
			umsg.Short( pl.Petrol )
		umsg.End( )
	
	end

end

end

if ( CLIENT ) then

function GetPlayerPetrol( um )

	-- Get the petrol value from the server as an INTEGER
	local amount = um:ReadShort( )
	
	-- Add it to the string when we print it.
	print( "Petrol: " .. amount .. "%" )
	
end
usermessage.Hook( "playerpetrol", GetPlayerPetrol )

end[/lua]

Thanks mate, Solved my issue instantly, yep i don’t know anything about user messages i usually make my scripts either Client or server but never both tbh

[editline]09:52PM[/editline]

Thats fixed it, But is there an easier way to share variables between server and client?

Networked variables.