Turning a negative or positive number into a decimal for a gui indicator

  1. What do you want to achieve?
    I have a gui element that I want to be able to indicate how many votes are in favor or not in favor of something.
  2. What is the issue?
    I cant figure out how to turn a number of the number of players (max players is 4) into a percent (to put into the indicator frame’s position)
  3. What solutions have you tried so far?
    I tried just dividing as you can see in the print, which I thought worked until I realized the negatives existed and threw it off.

This is my current code:

game.ReplicatedStorage.UpgradePollEvents.SendUpgradeVotes.OnClientEvent:Connect(function(VoteSkew:number)
	--[[
	Middle = 0.5
	Left = 0
	Right = 1
	
	MiddleSkew = 0
	LeftSkew = -4 (Or whatever the current player count is in the negatives)
	RightSkew = 4 (Or whatever the current player count is)
	]]
	
	print(VoteSkew/#game.Players:GetPlayers())
	script.Parent.BoundingIndicatorFrame.Indicator.Position = UDim2.new(VoteSkew,0,script.Parent.BoundingIndicatorFrame.Indicator.Position.Y.Scale,0)
end)

Basically: How do I turn a negative number into a percent below 0.5? How do I make positive numbers also act simmilar?

I don’t understand what you are trying to achieve. Maybe a picture of the UI would help visualize the situation. Also some examples?

Assuming I have max players in the game (4) and all 4 players vote “yes” (which adds 1 to the VoteSkew) Then the VoteSkew that is put into the indicators position should be 1, if it is negative like -4 then it should be 0, and if VoteSkew is 0 then it should become 0.5. (Sorry if im bad at explaining this)

I think I understood what you want to do.

voteSkew / numPlayers / 2 + 0.5

1 Like

Here is a visual representation of what I want:

VoteSkew = 4
image

VoteSkew = 3
image

VoteSkew = 2
image

VoteSkew = 1
image

VoteSkew = 0
image

Then the opposite for negatives.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.