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

How can I make a script repeat on death?

I have two scripts I would like to repeat on death because the will automatically stop working on death

local InputService = game:GetService("UserInputService") local Players = game:GetService("Players")

local client = Players.LocalPlayer local backpack = client:WaitForChild("Backpack") local character = client.Character or client.CharacterAdded:Wait()

local tools = backpack:GetChildren() local toolIndex = 1

local function add(v, x) return v + (x or 1) end

local function sub(v, x) return v - (x or 1) end

local function unequipTools() for _, item in next, character:GetChildren() do if item:IsA("Tool") then item.Parent = backpack end end end

local function mouseScrolled(dir) local numTools = #tools unequipTools()

toolIndex = dir and add(toolIndex) or sub(toolIndex)


toolIndex = toolIndex < 1 and numTools or toolIndex > numTools and 1 or toolIndex


local tool = tools[toolIndex] 
tool.Parent = character

end

InputService.InputChanged:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseWheel then mouseScrolled(input.Position.Z > 0) end end)

and

local player = game.Players.LocalPlayer

player.CameraMode = Enum.CameraMode.LockFirstPerson

1 comment

0

also how do you get the view source for scripts

1 answer

The CharacterAdded event fires when a player's character spawns (or respawns).

also how do you get the view source for scripts

To help with malicious intentions this feature was removed from roblox.

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