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

Reload Remote Event fires but doesn't update IntValues?

I got a tool with 3 IntValues: Mag, MagSize, and Reservoir. When the player presses R, it's supposed to reload their gun, but as I stated in the title, the reload event fires but the values do not update. I should mention both script snippets are inside the tool so I don't know if that's affecting it. Also I'm not completely get what you're supposed to put in the parentheses after the functions so that might be affecting it as well.

Local Script:

CanReload = false

function OnEquipped(playerMouse)
	CanReload = true
	local clone = GUI:Clone()
	local TextLabel = clone:WaitForChild("TextLabel")
	TextLabel.Text = Mag.Value.."/"..Reservoir.Value
	clone.Parent = Player.PlayerGui
	Mouse = playerMouse
	ExpectingInput = true
	UpdateMouseIcon()
end

function OnUnequipped()
	CanReload = false
	if Player.PlayerGui:FindFirstChild("Magazine") then
	Player.PlayerGui.Magazine:Destroy()
	end
	ExpectingInput = false
	UpdateMouseIcon()
end

Tool.Equipped:Connect(OnEquipped)
Tool.Unequipped:Connect(OnUnequipped)

UIS.InputBegan:Connect(function(Input)
	local reloaddebounce = false
	if Input.KeyCode == Enum.KeyCode.R then
		if CanReload then
				reloaddebounce = true
				Reload:FireServer(Tool)
				wait(1)
				reloaddebounce = false
		end
	end
end)

UserInputService.InputBegan:Connect(function (input, gameHandledEvent)
	if gameHandledEvent or not ExpectingInput then
	return
end

Mag.Changed:Connect(function(Tool)
	if Player.PlayerGui:FindFirstChild("Magazine") and Player.PlayerGui:FindFirstChild("Magazine"):FindFirstChild("TextLabel") then
		Player.PlayerGui.Magazine.TextLabel.Text = Mag.Value.."/"..Reservoir.Value
	end
end)
	
Reservoir.Changed:Connect(function(Tool)
	if Player.PlayerGui:FindFirstChild("Magazine") and Player.PlayerGui:FindFirstChild("Magazine"):FindFirstChild("TextLabel") then
		Player.PlayerGui.Magazine.TextLabel.Text = Mag.Value.."/"..Reservoir.Value
	end
end)

Script:

ReloadEvent.OnServerEvent:Connect(function(clientThatFired, Tool)
	local needed = MagSize.Value - Mag.Value 
	if Reservoir.Value < needed then
		Mag.Value = Mag.Value + Reservoir.Value
		Reservoir.Value = 0
	else
		Mag.Value = Mag.Value + needed
		Reservoir.Value = Reservoir.Value - needed
	end
end)

Sorry for bad script layout, I'm big nob.

1 answer

It appears your LocalScript has a syntax error on line 38- you failed to close the ( and add an end to the if statement on line 39. If you have any additional issues, make sure you add prints to both the client and server code to ensure everything is running properly, and make sure to keep an eye on the console for errors.

If you found this answer helpful, do mark it as one.

1 comment

0

That's weird, I'm not getting any errors.

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