Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Make Variable work For Multiple Players?

Asked by 3 years ago

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)
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). imKirda 4491 — 3y
0
ProximityPrompts can't be used on Client SitaruDaniel 44 — 3y
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 imKirda 4491 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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.

0
I mean all players affect the same variable. Thanks for trying to help but not what I'm looking for. SitaruDaniel 44 — 3y
0
This would affect all players, my friend. It can be used by all. (as long as it is server side) lsltReaIIyYou 64 — 3y
0
i would use BoolValues for this situation CrazyCats84 154 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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)


Answer this question