I'm trying to make it that if you pet your pet dog, it will give you money and +2 of joy. There is also joy, where it decreases by 1 every second. But whenever I try to pet the dog, it gives the error.
Code for the services
local HungerDecrease = 1
local joydecrease = 1
game.Players.PlayerAdded:Connect(function(Player)
local PetHunger = Instance.new("IntValue", Player)
PetHunger.Name = "Hunger"
PetHunger.Value = 100
Player.CharacterAdded:Connect(function()
PetHunger.Value = 100
end)
while wait(HungerDecrease) do
PetHunger.Value -= HungerDecrease
workspace.Doge.hunger.TextLabel.Text = "Hunger: "..PetHunger.Value
if PetHunger.Value == 0 then
Player:Kick("Doge starved")
end
end
end)
game.Players.PlayerAdded:Connect(function(Player)
local PetJoy = Instance.new("IntValue", Player)
PetJoy.Name = "Hunger"
PetJoy.Value = 100
Player.CharacterAdded:Connect(function()
PetJoy.Value = 100
end)
while wait(joydecrease) do
PetJoy.Value -= joydecrease
if PetJoy.Value == 100 then
workspace.Doge.joy.TextLabel.Text = "Joy: Very Happy"
end
if PetJoy.Value == 75 then
workspace.Doge.joy.TextLabel.Text = "Joy: Happy"
end
if PetJoy.Value == 50 then
workspace.Doge.joy.TextLabel.Text = "Joy: Bored"
end
if PetJoy.Value == 25 then
workspace.Doge.joy.TextLabel.Text = "Joy: Sad"
end
if PetJoy.Value == 0 then
Player:Kick("Doge is depressed")
end
end
end)
code for petting your pet
local Doge = script.Parent
local PSS = game:GetService("ProximityPromptService")
local bark = Doge.dogbark
PSS.PromptTriggered:Connect(function(prompt, player)
if prompt.Name == "Pet" then
local PlayerCash = player.leaderstats.cash
local PetJoy = player.PetJoy
PlayerCash.Value = PlayerCash.Value + 1
PetJoy.Value = PetJoy.Value + 2
bark:Play()
end
end)
