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

Why isnt the value changing?

Asked by 3 years ago

I am using a RemoteEvent to change value's globally from a LocalScript, this is for gun. Any suggestions or changes?

LocalScript:

elseif key.KeyCode == Enum.KeyCode.Q and tool:GetAttribute("hasAuto") == true then --Ignore
    db = false
    print(mode.Value)
    if mode.Value > 2 then
        tool.ModeEvent:FireServer("Mode", 1) --Line I'm having an issue with
    end
    tool.ModeEvent:FireServer("Mode", mode.Value + 1) --Works perfectly
    if mode.Value == 1 then
        tool.ModeEvent:FireServer("isAuto", false)
    elseif mode.Value == 2 then
        tool.ModeEvent:FireServer("isAuto", true)
    end
    wait(1)
    db = true
end

Script:

tool.ModeEvent.OnServerEvent:Connect(function(player, value, mode)
    tool:FindFirstChild(value).Value = mode
end)

1 answer

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

Local script line 4: change ">2" to ">=2" ?

Edit: actually, what you're doing is checking if a value is 2+ and if it is you're setting it to 1... But then straight afterwards you're setting it back to +1. Maybe move the +1 part into an "else" section of the preceding "if" statement?

elseif key.KeyCode == Enum.KeyCode.Q and tool:GetAttribute("hasAuto") == true then --Ignore
    db = false
    print(mode.Value)
    if mode.Value >= 2 then --changed
        tool.ModeEvent:FireServer("Mode", 1) --Line I'm having an issue with
    else --moved
        tool.ModeEvent:FireServer("Mode", mode.Value + 1) --Works perfectly 
    end

    if mode.Value == 1 then
        tool.ModeEvent:FireServer("isAuto", false)
    elseif mode.Value == 2 then
        tool.ModeEvent:FireServer("isAuto", true)
    end
    wait(1)
    db = true
end
0
saved me a few days dizzyjamison08 30 — 3y
0
Haha, you're welcome! Thanks for accepting the answer. AlexTheCreator 461 — 3y
Ad

Answer this question