I am new on scripting and I can't seem to figure out how to make it so when the I press on the screen the script runs. I'm trying to make a transformation as a tool. I found a YT video by Blur but instead of the transformation being a tool it's just the script and when you press P you transform. How do I make it so when I press the screen I transform and when I press it again I go back to normal?
Here's the Local Script that is in the starterpack:
local player = game.Players.LocalPlayer local uis = game:GetService("UserInputService") local remote = game.ReplicatedStorage:WaitForChild("Transformation") local ts = game:GetService("TweenService") repeat wait(1)until player.Character.Parent == workspace local char = player.Character local debounce = false local active = false local cd = 1 local cam = game.Workspace.CurrentCamera local hum = char:WaitForChild("Humanoid") uis.InputBegan:Connect(function(input,IsTpying) if input.keyCode == Enum.KeyCode.P and IsTpying == false then if debounce == false then debounce = true if active == false then cam.CameraType = Enum.CameraType.Scriptable cam.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0,0,-5))*CFrame.Angles(0,math.rad(180),0) ts:Create(cam,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0,-1,-4))*CFrame.Angles(0,math.rad(180),0)}):Play() remote:FireServer(active) active = true elseif active == true then cam.CameraType = Enum.CameraType.Scriptable cam.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0,0,-3))*CFrame.Angles(0,math.rad(180),0) ts:Create(cam,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0,0,-4))*CFrame.Angles(0,math.rad(180),0)}):Play() remote:FireServer(active) active = false end end end end) remote.OnClientEvent:Connect(function() cam.CameraType = Enum.CameraType.Custom wait(cd) debounce = false end)
My version of the script inside the tool:
local player = game.Players.LocalPlayer local uis = game:GetService("UserInputService") local remote = game.ReplicatedStorage:WaitForChild("Transformation") local ts = game:GetService("TweenService") local mouse = game.Players.LocalPlayer:GetMouse() local char = player.Character local debounce = false local active = false local cd = 1 local cam = game.Workspace.CurrentCamera local hum = char:WaitForChild("Humanoid") local tool = game.StarterPack.Bloodlust tool.RequiresHandle = false tool.Parent = game.Players.LocalPlayer.Backpack function onActivation() print("Tool activated") end tool.Activated:Connect(onActivation) repeat wait(1)until player.Character.Parent == workspace if debounce == false then debounce = true if active == false then cam.CameraType = Enum.CameraType.Scriptable cam.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0,0,-5))*CFrame.Angles(0,math.rad(180),0) ts:Create(cam,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0,-1,-4))*CFrame.Angles(0,math.rad(180),0)}):Play() remote:FireServer(active) active = true elseif active == true then cam.CameraType = Enum.CameraType.Scriptable cam.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0,0,-3))*CFrame.Angles(0,math.rad(180),0) ts:Create(cam,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0,0,-4))*CFrame.Angles(0,math.rad(180),0)}):Play() remote:FireServer(active) active = false end end end end) remote.OnClientEvent:Connect(function() cam.CameraType = Enum.CameraType.Custom wait(cd) debounce = false end)
The Script in serverscriptservice:
local remote = game.ReplicatedStorage:WaitForChild("Transformation") remote.OnServerEvent:Connect(function(plr,active) local char = plr.Character if active == false then for i,v in pairs(char:GetChildren())do if v:IsA("Part")then game:GetService("TweenService"):Create(v,TweenInfo.new(.7,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Color = Color3.fromRGB(132, 8, 8)}):Play() v.Material = Enum.Material.Neon end end local Sound1 = script:WaitForChild("DBZ_Beam_Charge"):Clone() Sound1.Parent = char.HumanoidRootPart Sound1:Play() game.Debris:AddItem(Sound1,2) local pushmodel = script:WaitForChild("Push"):Clone() pushmodel.Parent = workspace pushmodel.Core.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0,-1,0)) for i,v in pairs(pushmodel:GetChildren())do v.Anchored = true local tween = game:GetService("TweenService"):Create(v,TweenInfo.new(1,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Size = v.Size + Vector3.new(10,10,10),CFrame = v.CFrame * CFrame.Angles(0,math.rad(180),0)}) tween:Play() tween.Completed:Connect(function() local tween2 = game:GetService("TweenService"):Create(v,TweenInfo.new(.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0),{Transparency = 1}) tween2:Play() tween2.Completed:Connect(function() game.Debris:AddItem(v,0) end) end) end spawn(function() wait(1) local flash = script:WaitForChild("Flash"):Clone() flash.Parent = plr.PlayerGui game.Debris:AddItem(flash,.5) local sound2 = script:WaitForChild("Explosion"):Clone() sound2.Parent = char.HumanoidRootPart sound2:Play() game.Debris:AddItem(sound2,1.5) for i,v in pairs(char:GetChildren())do if v:IsA("Part")then v.Material = Enum.Material.Plastic end end end) local BeamEffect = script:WaitForChild("BeamEffect"):Clone() BeamEffect.Parent = char BeamEffect.CFrame = char.HumanoidRootPart.CFrame local weld = Instance.new("Weld") weld.Part0 = char.HumanoidRootPart weld.Part1 = BeamEffect weld.Name = "TransformationWeld" weld.Parent = weld.Part0 char.Humanoid.Animator:LoadAnimation(script:WaitForChild("transformAnimation")):Play() local bodyVelocity = Instance.new("BodyVelocity",char.HumanoidRootPart) bodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge) bodyVelocity.Velocity = char.HumanoidRootPart.CFrame.LookVector*.0001 game.Debris:AddItem(bodyVelocity,.8) elseif active == true then if char:FindFirstChild("BeamEffect")then char:FindFirstChild("BeamEffect"):Destroy() end if char.HumanoidRootPart:FindFirstChild("TransformationWeld")then char.HumanoidRootPart:FindFirstChild("TransformationWeld"):Destroy() end char["Left Arm"].Color = char["Body Colors"].LeftArmColor3 char["Right Arm"].Color = char["Body Colors"].RightArmColor3 char["Torso"].Color = char["Body Colors"].TorsoColor3 char["Right Leg"].Color = char["Body Colors"].RightLegColor3 char["Left Leg"].Color = char["Body Colors"].LeftLegColor3 char["Head"].Color = char['Body Colors'].HeadColor3 local bodyVelocity = Instance.new("BodyVelocity",char.HumanoidRootPart) bodyVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge) bodyVelocity.Velocity = char.HumanoidRootPart.CFrame.LookVector*.0001 game.Debris:AddItem(bodyVelocity,.8) end wait(1) remote:FireClient(plr) end)
The developer hub has a great article that could help with that issue. Check it out here.