Hi, I’m trying to activate a value from a tool, but I get the error : Unable to cast value to Object
Script of the tool :
`local tool = script.Parent
local equipped = false
local UID = game:GetService(“UserInputService”)
local test = game.ReplicatedStorage.ItemsEvents.ElfSwordEquippedEvent
local un = true
tool.Equipped:Connect(function()
test:FireClient(un)
end)
tool.Unequipped:Connect(function()
local un = false
test:FireClient(un)
end)
UID.InputBegan:Connect(function(key,isTyping)
if isTyping == false then
if equipped == true then
print(“tool equipped”)
if key.KeyCode == Enum.KeyCode.F then
print(“pressed f”)
local character = game.Players.LocalPlayer.Character
game.ReplicatedStorage.ItemsEvents.ElfSwordEvent:FireServer(character)
print(“fired server”)
end
end
end
end)`
Script of the character :
`local equipped = false
local UID = game:GetService(“UserInputService”)
local localplayer = game.Players.LocalPlayer
local character = game.Players.LocalPlayer.Character
local test = game.ReplicatedStorage.ItemsEvents.ElfSwordEquippedEvent
UID.InputBegan:Connect(function(key,isTyping)
if isTyping == false then
if key.KeyCode == Enum.KeyCode.F and game.Players.LocalPlayer.ElfSword.Value == true then
local test = game.ReplicatedStorage.ItemsEvents.ElfSwordEquippedEvent
local character = game.Players.LocalPlayer.Character
test.OnClientEvent:Connect(function(un)
if un == false then
game.Players.LocalPlayer.ElfSword.Value = false
end
if un == true then
local character = game.Players.LocalPlayer.Character.Humanoid.MaxHealth
character = 10000
local a = game.Players.LocalPlayer.Character.Humanoid.Health
a = 10000
end
end)
if a == false then
test.OnClientEvent:Connect(function(un)
end)
end
game.ReplicatedStorage.ItemsEvents.ElfSwordEvent:FireServer(character)
print("fired server")
end
end
end)
local ElfSword = game.Players.LocalPlayer.Backpack:FindFirstChild(“Elf Sword”)
test.OnClientEvent:Connect(function(un)
end)`
Script of the leaderstats :
`game.Players.PlayerAdded:Connect(function(player)
local leaderstats= Instance.new(“Folder”)
leaderstats.Name= (“leaderstats”)
leaderstats.Parent= player
--now currency
local ElfSword= Instance.new("BoolValue")
ElfSword.Name= ("ElfSword")
ElfSword.Parent = player
end)`