Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why can't I destory the pet?

Asked by
VipDanT 10
1 year ago
Edited 1 year ago

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)

0
Are there any error messages? hattim00 80 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

[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)
Ad

Answer this question