Why does LocalScript error accessing Cooldown (NumberValue) while server script works fine?

TileClickScript claims Cooldown (NumberValue) isn’t a valid member of script.Parent, however, another script runs normally. TileClickScript is a LocalScript, so can they not access Values?

I am going to make Cooldown an attribute, but I was just wondering for future reference.


TileClickScript (local script):

local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()
local shovel = script.Parent
local tileEvent = shovel.TileEvent
local map = workspace.Map
local tiles = map.Tiles

local debounce

local COOLDOWN = script.Parent.Cooldown.Value

-- Puts a TargetFilter on all characters so the mouse can ignore them.
for _, player in Players:GetPlayers() do
	local character = player.Character
	mouse.TargetFilter = character
end

-- Runs when the player left-clicks.
local function onButton1Down()
	local target = mouse.Target

	if debounce == true then
		return
	else
		debounce = true
		
		-- If the mouse's target is a tile, then fire TileEvent.
		if target:IsDescendantOf(tiles) then
			tileEvent:FireServer(target)
		end
		
		wait(COOLDOWN)
		debounce = false
	end
end

mouse.Button1Down:Connect(onButton1Down)

Animate (server script):

local shovel = script.Parent
local animateFolder = shovel.Animations
local animations = {
	ShovelHoldAnim = animateFolder.ShovelHoldAnim,
	ShovelBashAnim = animateFolder.ShovelBashAnim
}

local debounce

local COOLDOWN = script.Parent.Cooldown.Value

-- Runs when a player equips a shovel.
local function onEquipped()
	local humanoid = shovel.Parent:FindFirstChild("Humanoid")
	animator = humanoid:FindFirstChild("Animator")

	holdAnimTrack = animator:LoadAnimation(animations["ShovelHoldAnim"])
	holdAnimTrack.Priority = Enum.AnimationPriority.Action
	holdAnimTrack:Play() -- Plays the shovel holding animation.
end

-- Runs when a player unequips the shovel.
local function onUnequipped()
	holdAnimTrack:Stop() -- Stops the shovel holding animation.
end

-- Runs when the shovel activates.
local function onActivated()
	if debounce == true then
		return
	else
		debounce = true
		local bashAnimTrack = animator:LoadAnimation(animations["ShovelBashAnim"])
		bashAnimTrack:Play() -- Plays the shovel bashing animation.
		
		wait(COOLDOWN)
		debounce = false
	end
end

shovel.Equipped:Connect(onEquipped)
shovel.Unequipped:Connect(onUnequipped)
shovel.Activated:Connect(onActivated)


When I ran a print statement:

1 Like

Hello, this is probably because the client script is running too fast so the Cooldown value is not instanced at the moment its trying to find the value, try that in your LocalScript:

local cooldownValue = script.Parent:WaitForChild('Cooldown', 15)
local COOLDOWN = cooldownValue.Value
1 Like

Solution: use wait for child becouse it could’ve had not replicated (loaded) to a client yet

local tileEvent = shovel:WaitForChild"TileEvent"

You can call functions like that btw, pretty cool right?
Also does work with some other data types like table for example:

print{FunnyTable=true}

Also replace wait into task.wait becouse its a more modernized function

Also is kinda bad creating function like that becouse closure would’ve been better:

local function onButton1Down()
	local target = mouse.Target

Like that:

local target = mouse.Target
local function onButton1Down():()
	

I added :() to the end of function telling script analisis that function doesnt return anything at all.

1 Like

Thank you, that was a surprisingly easy fix.

1 Like

That’s pretty neat. Thank you!

1 Like