Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Make Variable work For Multiple Players?

So this script only works for one player, having only one variable meaning that one player can hover with mouse over and the other person doesnt have to do it. I can't use localscripts as this is ProximityPrompt. Any way I can do this?

Part of Script:

local isHovering = false

script.Parent.ClickDetector.MouseHoverEnter:Connect(function()
	isHovering = true
end)

script.Parent.ClickDetector.MouseHoverLeave:Connect(function()
	isHovering = false
end)

script.Parent.ProximityPrompt.PromptButtonHoldBegan:Connect(function(plr)
	if isHovering == true then
		local value = plr.PlayerGui.PickupCircle.ArcBar.CBar.Fill.Value
		plr.PlayerGui.PickupCircle.ArcBar.Visible = true
		Tween = ts:Create(value,Info,Goal)
		Tween:Play()
	end
end)

4 comments

0

Just switch to local scripts, it is the easiest and best method, ProximityPrompts can be used on the client, you would just need to use RemoteEvents (with simple anti remote exploits).

0

ProximityPrompts can't be used on Client

0

Why so? They can, the problem is that your script must be located in container in which it can run in (StarterPlayerScripts is the best), local scripts don't run in the workspace so if you change references to the Prompt and put it into any of the client containers it will work without any problems

2 answers

I recommend you use an _G value (Global) like so:

_G.isHovering = false

script.Parent.ClickDetector.MouseHoverEnter:Connect(function()
_G.isHovering = true
end)

script.Parent.ClickDetector.MouseHoverLeave:Connect(function()
_G.isHovering = false
end)

script.Parent.ProximityPrompt.PromptButtonHoldBegan:Connect(function(plr)
    if _G.isHovering == true then
        local value = plr.PlayerGui.PickupCircle.ArcBar.CBar.Fill.Value
        plr.PlayerGui.PickupCircle.ArcBar.Visible = true
        Tween = ts:Create(value,Info,Goal)
        Tween:Play()
    end
end)

Keep in mind you will have to rename the part after "_G." for each script so that you don't accidentally set two parts at the same time. More here.

3 comments

0

I mean all players affect the same variable. Thanks for trying to help but not what I'm looking for.

0

This would affect all players, my friend. It can be used by all. (as long as it is server side)

0

i would use BoolValues for this situation

Found the solution. Create a stringvalue for each player that you can change to know if the mouse is hovering over part.

This is the script:

local ts = game:GetService("TweenService")
local Info = TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.In,0,false,0)
local Goal = {Value = 38}
local Tween
local isHoveringVal

game.Players.PlayerAdded:Connect(function(plr)
	isHoveringVal = Instance.new("StringValue")
	isHoveringVal.Name = "Hover"
	isHoveringVal.Parent = plr
	isHoveringVal.Value = "NotHovering"
end)

script.Parent.ClickDetector.MouseHoverEnter:Connect(function(plr)
    isHoveringVal.Value = "Hovering"
end)

script.Parent.ClickDetector.MouseHoverLeave:Connect(function(plr)
	isHoveringVal.Value = "NotHovering"
end)

script.Parent.ProximityPrompt.PromptButtonHoldBegan:Connect(function(plr)
	if isHoveringVal.Value == "Hovering" then
		local value = plr.PlayerGui.PickupCircle.ArcBar.CBar.Fill.Value
		plr.PlayerGui.PickupCircle.ArcBar.Visible = true
		Tween = ts:Create(value,Info,Goal)
		Tween:Play()
	end
end)

script.Parent.ProximityPrompt.PromptButtonHoldEnded:Connect(function(plr)
	local value = plr.PlayerGui.PickupCircle.ArcBar.CBar.Fill.Value
	plr.PlayerGui.PickupCircle.ArcBar.Visible = false
	Tween:Pause()
	value.Value = 1
end)

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	script.Parent:Destroy()
end)


This discussion is preserved as it was. New answers, comments, and votes are closed.