Local script not destroying

I made a script to detect if a player is on mobile, if they are i will destroy the script.

This is my code

local ismobile = game:GetService('UserInputService').TouchEnabled



local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()

if ismobile == true then
	script.Parent.punch:Destroy()
end


mouse.Button1Down:Connect(function()
	local playermodel = game.Workspace:FindFirstChild(player.Name)
		playermodel.punchevent:FireServer()

end)

im a beginner so dont blame me if this is an easy fix : /

Send a screenshot of the output log and explorer.

The outputs pretty messy but theres nothing that came from the script.
heres the explorer

Check if your if statement actually works by adding a print inside.

1 Like

Instead of using script.Parent.punch:Destroy() use script:Destroy()

i’ve already tried that and it didnt work.

If the if statement does print and what @NotFrindow suggested still doesn’t work, you could try :Disconnect()ing the .ButtonOneDown event.

local ismobile = game:GetService('UserInputService').TouchEnabled



local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local con

if ismobile == true then
	script:Destroy()
    con:Disconnect()
end


con = mouse.Button1Down:Connect(function()
	local playermodel = game.Workspace:FindFirstChild(player.Name)
		playermodel.punchevent:FireServer()

end)

Sorry if it isn’t formatted correctly, it’s tough typing on a phone.

it seems to have worked. Thanks for your help.