Hello, I am currently trying to make a button that when pressed spawns a model in front of me but I am having trouble figuring out why the script that is in the model is not working when I spawn the it. I could really use some help.
script in model:
function slowDown(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
humanoid.WalkSpeed = 5
end
end
function ResetSpeed(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local humanoid = hit.Parent:FindFirstChild("Humanoid")
humanoid.WalkSpeed = 16
end
end
Part.Touched:Connect(slowDown)
Part.TouchEnded:Connect(ResetSpeed)
script in button:
script.Parent.MouseButton1Click:Connect(function()
local HRP = game.Players.LocalPlayer.Character.HumanoidRootPart
local model = game.ReplicatedStorage.Yrden:Clone()
local distance = 10 -- distance between the model and the character
local pos = HRP.Position + (HRP.CFrame.LookVector)*distance
model.Parent = workspace
model:MoveTo(pos)
wait(10)
game.Workspace.Yrden:Destroy()
end)
Hey if you could edit your post and format the code using ``` at the beginning and endings it would make it a lot easier to read. Could you also provide script outputs and a better explanation? Is that video your desired outcome or is that the issue?
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
local HRP = player.Character.HumanoidRootPart
local model = game.ReplicatedStorage.Yrden:Clone()
local distance = 10 -- distance between the model and the character
local pos = HRP.Position + (HRP.CFrame.LookVector)*distance
model.Parent = workspace
model.PrimaryPart.CFrame = CFrame.new(HRP.Position + HRP.CFrame.LookVector * distance)
game:GetService("Debris"):AddItem(game.Workspace.Yrden,10)
end)