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

How to make tools without Tool.Activated work on mobile?

This is my first time using Scripting support, i apologize if there were a mistake.

I am still mediocre at scripting, sorry if i misunderstood some parts.

I wanted to make my tool work with mobile, but the tool doesn't work with OnActivated()

I used roblox Golden Steampunk as my tool template to make my tool.

i was making a bat tool that works similar as the 'be dead forever simulator' bat, where when you used it, you can't move but kills anything.

How will i make it so the tool works when you tap as mobile? My server script:

local Tool = script.Parent
local StartEvent = Tool:WaitForChild("Start")
local Remote = Tool:WaitForChild("Remote")
local Handle = Tool:WaitForChild("Handle")

local FriendlyFire = false

local char = Tool.Parent

local HitAble = false
local HitWindup = 3.15
local HitWindow = 0.75
local HitDamage = 500
local HitVictims = {}

local SwingAble = true
local SwingRestTime = 9.5

--returns the wielding player of this tool
function getPlayer()
	local char = Tool.Parent
	return game:GetService("Players"):GetPlayerFromCharacter(char)
end

--helpfully checks a table for a specific value
function contains(t, v)
	for _, val in pairs(t) do
		if val == v then
			return true
		end
	end
	return false
end

--tags a human for the ROBLOX KO system
function tagHuman(human)
	local tag = Instance.new("ObjectValue")
	tag.Value = getPlayer()
	tag.Name = "creator"
	tag.Parent = human
	game:GetService("Debris"):AddItem(tag)
end

--used by checkTeams
function sameTeam(otherHuman)
	local player = getPlayer()
	local otherPlayer = game:GetService("Players"):GetPlayerFromCharacter(otherHuman.Parent)
	if player and otherPlayer then
		if player == otherPlayer then
			return true
		end
		if otherPlayer.Neutral then
			return false
		end
		return player.TeamColor == otherPlayer.TeamColor
	end
	return false
end

--use this to determine if you want this human to be harmed or not, returns boolean
function checkTeams(otherHuman)
	return not (sameTeam(otherHuman) and not FriendlyFire)
end

function onTouched(part)
	if part:IsDescendantOf(Tool.Parent) then return end
	if not HitAble then return end
	
	if part.Parent and part.Parent:FindFirstChild("Humanoid") then
		local human = part.Parent.Humanoid
		
		if contains(HitVictims, human) then return end
		
		local root = part.Parent:FindFirstChild("HumanoidRootPart")
		if root and not root.Anchored then
			local myRoot = Tool.Parent:FindFirstChild("HumanoidRootPart")
			if myRoot and checkTeams(human) then
				local delta = root.CFrame.Position - myRoot.CFrame.Position -- make the enemy face me
				
				tagHuman(human)
				human:TakeDamage(HitDamage)
				root.CFrame = CFrame.new(root.Position, myRoot.Position)
				table.insert(HitVictims, human)
				
				tagHuman(human)
				human:TakeDamage(HitDamage)
				root.Anchored = false
				root.Massless = false
				table.insert(HitVictims, human)

				local bv = Instance.new("BodyVelocity", root)
				bv.maxForce = Vector3.new(1e9, 1e9, 1e9)
				bv.velocity = delta.Unit * 125
				game:GetService("Debris"):AddItem(bv, 0.1)

				-- sounds
				Handle.Homerun:Play() 
				Handle.Smack:Play()
				Handle.bawnk:Play()
				
				wait(4)
				
				Handle.Voiceline3:Play()
			end
		end
	end
end

local function onLeftDown(property)
	if not SwingAble then return end
	Tool.Parent:WaitForChild("HumanoidRootPart").Anchored = true
	Tool.Parent:WaitForChild("HumanoidRootPart").Massless = true
	
	SwingAble = false
	StartEvent:FireClient(getPlayer()) -- activates the camera script
	delay(SwingRestTime, function()
		SwingAble = true
	end)
	
	delay(HitWindup, function()
		HitAble = true
		Handle.Boom:Play()
		delay(HitWindow, function()
			HitAble = false
		end)
	end)
	
	HitVictims = {}
	
	Remote:FireClient(getPlayer(), "PlayAnimation", "Swing")
	
	wait(0.25)
	script.Parent.Handle.StartVoiceline1:Play()
	wait(2)
	Handle.TauntVoiceline2:Play()
	wait(1)
	Handle.Trail.Enabled = true
	wait(1.4)
	Tool.Parent:WaitForChild("HumanoidRootPart").Anchored = false
	Tool.Parent:WaitForChild("HumanoidRootPart").Massless = false
	Handle.Trail.Enabled = false
end

function onRemote(player, func, ...)
	if player ~= getPlayer() then return end
	
	if func == "LeftDown" then
		onLeftDown(...)
	end
end

Handle.Touched:connect(onTouched)
Remote.OnServerEvent:connect(onRemote)

1 comment

0

Why do you not want to use Tool.Activated?

1 answer

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