You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Sorry, I am new to scripting and this is pretty much my first post here. This is my first game.
I wish for the tool to work after death.
Thank you for any help given, it is muchly appreciated
-
What is the issue? Include screenshots / videos if possible!
The tool stops working after death. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
GUI reset on spawn for inventory doesn’t work. Also stops the inventory system from working.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
--[[
Local script within tool
This tool when activated teleports the player to the clicked spot.
When equipped it clones a part which is a child of the tool to the cursor, the part turns red if the it goes out side of
the allowed range and blue inside of the allowed range.
When unquipped it destroys the part.
--]]
--- Services ---
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
local ServerScriptService = game:GetService("ServerScriptService")
--- Folders ---
local eventsFolder = ReplicatedStorage:WaitForChild("Events")
local debrisFolder = workspace:WaitForChild("DebrisFolder")
--- Player ---
local mouse = game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer
local skillFolder = player:WaitForChild("SkillsFolder")
local statsFolder = player:WaitForChild("PlayerStats")
local spatialMagic = skillFolder:WaitForChild("Spatial Magic")
local character = player.Character or player.CharacterAdded:Wait()
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
local mana = statsFolder:WaitForChild("Mana")
--- Events ---
local Event = eventsFolder:WaitForChild("Teleport")
--- Other Variables ---
local tool = script.Parent
local range = 5 + spatialMagic.Value
local equiped = false
--- this function runs when the tool is equipped ---
local function Equip()
local teleArea = tool:WaitForChild("TeleArea")
local teleClone = teleArea:Clone()
equiped = true
teleClone.Parent = workspace.DebrisFolder
teleClone.Name = teleArea.Name .. player.Name
while equiped do
task.wait()
teleClone.Position = mouse.Hit.Position
teleClone.Transparency = 0
if (teleClone.Position - HumanoidRootPart.Position).Magnitude <= range then
teleClone.Color = Color3.fromRGB(0,0,255)
else
teleClone.Color = Color3.fromRGB(255,0,0)
end
end
end
--- this function runs when the tool is unequipped ---
local function Unequip()
equiped = false
for i, telePart in pairs(debrisFolder:GetChildren()) do
if telePart.Name == "TeleArea" .. player.Name then
telePart:Destroy()
end
end
end
--- this functions runs when the tool is activated ---
local function OnActivate()
if equiped and (mouse.Hit.Position - HumanoidRootPart.Position).Magnitude <= range then
Event:FireServer(mouse.Hit.Position)
end
end
--- connections ---
tool.Equipped:Connect(Equip)
tool.Unequipped:Connect(Unequip)
tool.Activated:Connect(OnActivate)
--[[
This script is located in Server Script Service.
It listens for the remote event sent from the teleport tool
--]]
--- Services ---
local ServerScriptService = game:GetService("ServerScriptService")
local replicatedStorage = game:GetService("ReplicatedStorage")
--- Folders ---
local eventsFolder = replicatedStorage:WaitForChild("Events")
--- Events ---
local event = eventsFolder:WaitForChild("Teleport")
local PopUpEvent = eventsFolder:WaitForChild("PopUpText")
--- Variables ---
local skillModule = require(ServerScriptService.SpellHandler.Modules.SkillModule)
-- This function runs when the remote event is sent
local function teleport(player, mouse)
--- player
local character = player.character
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
local statsFolder = player:WaitForChild("PlayerStats")
local mana = statsFolder:WaitForChild("Mana")
local SkillsFolder = player:WaitForChild("SkillsFolder")
local totalSkill = SkillsFolder:WaitForChild("Skills Total")
local maxSkill = SkillsFolder:WaitForChild("Max Skills Allowed")
local spatialMagic = SkillsFolder:WaitForChild("Spatial Magic")
--- variables
local manaCost = (mouse - HumanoidRootPart.Position).Magnitude
if mana.Value < manaCost then
PopUpEvent:FireClient(player, "NOT ENOUGH MANA!") -- fire event if insufficiecnt mana
return end
if mana.Value >= manaCost then
mana.Value -= manaCost
character:MoveTo(mouse)
skillModule.skillInc(totalSkill, maxSkill, spatialMagic) -- skill increase
end
end
--- Conections ---
event.OnServerEvent:Connect(teleport)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.