How would i go about scripting an abilities system

hello!

I am wondering how I would go about creating an abilities system for specific tools (like Allusions). I have a basic ability set up that i want to perform only when i am holding a specific weapon.

(weapon shown here)
Screenshot (34)

the ability makes you transparent whilst giving you a speed boost as shown here

--local script (placed in the tool)
local UIS = game:GetService('UserInputService')
local RS = game:GetService("ReplicatedStorage")
local A1 = RS:WaitForChild("A1")
local tool = script.Parent -- assuming your LocalScript is the child of the tool
local debounce = false

-- KeyPressed:

UIS.InputBegan:Connect(function(input)

	if input.KeyCode == Enum.KeyCode.E then
		A1:FireServer(tool) -- may include other arguments if needed
		debounce = true
		wait(2)
		debounce = false
	end
end)
-- server script (placed in StarterCharacterScripts)
local RS = game:GetService("ReplicatedStorage") --gets rstorage
local A1 = RS:WaitForChild("A1") --finds the remote event
local toolOne = nil -- define your tools if needed

A1.OnServerEvent:Connect(function(plr, tool) --catches the signal made from the input
	print("fired event") --checks if the remote event fired
	print(plr, tool) -- checks who gave the signal and what weapon they have
	local plrChar = plr.Character --finds the signal giver's character
	local findTool = plrChar:FindFirstChild(tool.Name) --finds the tool name
	print(findTool) --double checks the tool name


	if not findTool then -- runs if there is no tool 
		print("tool not found")
		return end

	-- now you can run specific actions depending on the tool
	if findTool == "Scythe" then --should run if the player is holding the Scythe
		print("Move Successful!")
		local children = plrChar:GetChildren()
		local originalwalkspeed = plrChar.Humanoid.WalkSpeed
		plrChar.Humanoid.WalkSpeed = 50

		for i, v in pairs(children) do --makes all parts of the player transparent
			--if v.Name == "HumanoidRootPart" then return end
			if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
				v.Transparency = 0.8
			end	
		end
		wait(1)
		plrChar.Humanoid.WalkSpeed = originalwalkspeed
		for i, v in pairs(children) do --makes all parts of the player non-transparent
			--if v.Name == "HumanoidRootPart" then return end
			if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
				v.Transparency = 0
			end	
		end
		wait(2)
	end

	if findTool == toolOne then
		print("Player wants to do an action with this specific tool")
	end
end)

my main problem here is that the signal from the button input works, but it does not want to perform the ability.

help would be appreciated

1 Like

I tried looking at you script, I don’t see anywhere why the function wouldn’t be firing. But maybe instead of using remote events, keep the ability inside the tool local script.

it wouldn’t replicate the ability to the server though i think

i will try and see if it replicates to the server

It doesn’t appear to replicate to the server. To think I spent all this time creating an alternative :joy:

@TheStoneBros

Sorry for the numerous replies, as i am fixing it in real time, i added a print statement

print(findTool == "Normal Tool")

and it came out false, (i changed the name of the tool for testing purposes). Even thought the tool name and the findTool line up? Weird.
I have it, the findtool variable is coming out as in instance as when I tried to print it using print("|"..findTool.."|") it came out with the error:
Workspace.DaBoss4344.Script:12: attempt to concatenate Instance with string as it is using find first child. So, it returns a instance instead. What you want to do is this:

print("fired event") --checks if the remote event fired
 -- checks who gave the signal and what weapon they have
	local plrChar = plr.Character --finds the signal giver's character
	local findTool = plrChar:FindFirstChild(tool.Name) --finds the tool name
	local toolname = findTool.Name

	if toolname == "Normal Tool" then

also, quick tip, you might want to also change the transparency of accessories and decals like this:

for i, v in pairs(children) do --makes all parts of the player transparent
			--if v.Name == "HumanoidRootPart" then return end
			if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
				v.Transparency = 0.8
			end	
			if v:IsA("Accessory") then
				v.Handle.Transparency = 0.8
			end	
			if v.Name == "Head" then
				v.face.Transparency = 0.8
			end	
		end
		wait(1)
		for i, v in pairs(children) do --makes all parts of the player transparent
			--if v.Name == "HumanoidRootPart" then return end
			if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
				v.Transparency = 0
			end	
			if v:IsA("Accessory") then
				v.Handle.Transparency = 0
			end
			if v.Name == "Head" then
				v.face.Transparency = 0
			end	

alright thank you, i used tostring and now it works!
your help is very appreciated

1 Like

updated script:

local RS = game:GetService("ReplicatedStorage") --gets rstorage
local A1 = RS:WaitForChild("A1") --finds the remote event
local toolOne = nil -- define your tools if needed

A1.OnServerEvent:Connect(function(plr, tool) --catches the signal made from the input
	print("fired event") --checks if the remote event fired
	print(plr, tool) -- checks who gave the signal and what weapon they have
	local plrChar = plr.Character --finds the signal giver's character
	local findTool = plrChar:FindFirstChild(tool.Name) --finds the tool name
	print(findTool) --double checks the tool name
	local SelectedTool = tostring(findTool)
	print(SelectedTool)


	if not SelectedTool then -- runs if there is no tool 
		print("tool not found")
		return end

	-- now you can run specific actions depending on the tool
	if SelectedTool == "Scythe" then --should run if the player is holding the Scythe
		print("Move Successful!")
		local children = plrChar:GetChildren()
		local originalwalkspeed = plrChar.Humanoid.WalkSpeed
		plrChar.Humanoid.WalkSpeed = 50

		for i, v in pairs(children) do --makes all parts of the player transparent
			--if v.Name == "HumanoidRootPart" then return end
			if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
				v.Transparency = 0.8
			end	
		end
		wait(1)
		plrChar.Humanoid.WalkSpeed = originalwalkspeed
		for i, v in pairs(children) do --makes all parts of the player non-transparent
			--if v.Name == "HumanoidRootPart" then return end
			if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
				v.Transparency = 0
			end	
		end
		wait(2)
	end

	if findTool == toolOne then
		print("Player wants to do an action with this specific tool")
	end
end)

No problems! I learnt a few things myself when helping you debug this script. I actually never knew tostring existed.

Have a good day,
DaBoss4344