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

Why can't I destory the pet?

I'm working on a simulator Link btw: https://web.roblox.com/games/9952086550/Donut-Eating-Simulator And this destroy pet doesn't work. Can someone please explain this? Here's the code: game.ReplicatedStorage.Remotes.UnequipPet.OnServerEvent:Connect(function(player, pet) if player.Character.Humanoid.Health ~= 0 then player.Character:FindFirstChild(pet):Destory(pet) end end)

Other part of code:

script.Parent.MouseButton1Click:Connect(function() if script.Parent.Text == "Equip" or script.Parent.Text == "Buy" then local result = game.ReplicatedStorage.RemoteFunctions.EquipPet:InvokeServer(script.Parent.Parent.Name) if result == "Bought" then script.Parent.Text = "Equipped" script.Parent.Text = "Unequip" elseif result == "Not enough coins" then script.Parent.Text = "Not enough Eaten" wait(1) script.Parent.Text = "Buy" elseif result == "Unequip" then script.Parent.Text = "Unequip" end elseif script.Parent.Text == "Unequip" then game.ReplicatedStorage.Remotes.UnequipPet:FireServer(script.Parent.Parent.Name) end end)

1 comment

0

Are there any error messages?

1 answer

[PLEASE MARK THIS ANSWER AS ACCEPTED IF THIS WORKS]

if this does not work leave a reply with any error message or let me know it does not work in the replies

Change the local script to:

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Text == "Equip" or script.Parent.Text == "Buy" then 
		local result = game.ReplicatedStorage.RemoteFunctions.EquipPet:InvokeServer(script.Parent.Parent.Name)
		if result == "Bought" then
			script.Parent.Text = "Equipped"
			script.Parent.Text = "Unequip"
		elseif result == "Not enough coins" then
			script.Parent.Text = "Not enough Eaten"
			wait(1)
			script.Parent.Text = "Buy"
		elseif result == "Unequip" then
			script.Parent.Text = "Unequip"
		end elseif script.Parent.Text == "Unequip" then
		game.ReplicatedStorage.Remotes.UnequipPet:FireServer(game.Players.LocalPlayer, script.Parent.Parent.Name, script.Parent.Parent) end
end)

Change the (server-sided) normal script to:

game.ReplicatedStorage.Remotes.UnequipPet.OnServerEvent:Connect(function(player, petName, petModel)
	if player.Character.Humanoid.Health ~= 0 then
		player.Character:FindFirstChild(petModel):Destory()
	end
end)

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