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: