Hi everyone. I created (merged few scripts into 1) script which allows me to change character model and give it tools by touching part. It all was fine untill I tried to rework it into GUI.
The issue After i click the button, character model changes, it gives me the tools and teleports me to the part but i can’t use ANY tools (I click them but nothing happens).
Output doesn’t show any errors too
Code for the part that morphs (this one works):
local giver = script.Parent
local morph = game.ReplicatedStorage.Character1.Character1Model
local CharTools = game.ReplicatedStorage.Character1.Tools
local debounce = true
giver.Touched:Connect(function(obj)
local plr = game.Players:GetPlayerFromCharacter(obj.Parent)
if plr and debounce == true then
giver.Color = Color3.new(255, 0, 0)
debounce = false
obj.Parent.HumanoidRootPart.CFrame = workspace["SpawnLocation"].CFrame
local charClone = morph:Clone()
charClone.Name = plr.Name
plr.Character = charClone
wait(1)
local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChild("Torso")
local plrRoot = obj.Parent:FindFirstChild("HumanoidRootPart") or obj.Parent:FindFirstChild("Torso")
if rootPart and plrRoot then
rootPart.CFrame = plrRoot.CFrame
end
charClone.Parent = workspace
wait(1)
CharTools["Tool1"]:clone().Parent = plr:FindFirstChild("Backpack")
CharTools["Tool2"]:clone().Parent = plr:FindFirstChild("Backpack")
CharTools["Tool3"]:clone().Parent = plr:FindFirstChild("Backpack")
CharTools["Tool4"]:clone().Parent = plr:FindFirstChild("Backpack")
end
wait(5)
giver.Color = Color3.new(163, 162, 165)
debounce = true
end)
Code for the gui button (This is the one with issue)
local CharMenu = game.Players.LocalPlayer.PlayerGui:WaitForChild("CharMenu")
local button = script.Parent.ImageButton
local Player = game.Players.LocalPlayer
local character = Player.Character
local morph = game.ReplicatedStorage.Character1.Character1Model
local CharTools = game.ReplicatedStorage.Character1.Tools
button.MouseButton1Click:Connect(function()
CharMenu.Enabled = false
character.HumanoidRootPart.CFrame = workspace["SpawnLocation"].CFrame
local charClone = morph:Clone()
charClone.Name = Player.Name
character = charClone
wait(1)
local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChild("Torso")
local plrRoot = character:FindFirstChild("HumanoidRootPart") or character:FindFirstChild("Torso")
if rootPart and plrRoot then
rootPart.CFrame = plrRoot.CFrame
end
charClone.Parent = workspace
wait(1)
CharTools["Tool1"]:clone().Parent = Player:FindFirstChild("Backpack")
CharTools["Tool2"]:clone().Parent = Player:FindFirstChild("Backpack")
CharTools["Tool3"]:clone().Parent = Player:FindFirstChild("Backpack")
CharTools["Tool4"]:clone().Parent = Player:FindFirstChild("Backpack")
end)
Also i know my code isn’t looking too great i might work on it later but first i want to get it to work.
Sidenote: You probably can see it but i was created the gui script based on the first one.
Im also pretty bad at scripting.
Oh and other thing i saw was that my old character model teleports to the spawnlocation with me and stays there, and it wasn’t happening in the old script