Hello
function onClick(noot) local val = script.Parent.Parent.TextBox.Value.Value local text = script.Parent.Parent.TextBox val = text.Text local plr = game.Players:FindFirstChild(val) local val2 = script.Parent.Parent.dis.Value.Value local text2 = script.Parent.Parent.dis val2 = text2.Text local item = game.ServerStorage.SponsorItems:FindFirstChild(val2) if plr and plr.Character and plr.Character:FindFirstChild("Arm1") and item then if val2 == "Food" then local foood = game.ServerStorage.SponsorItems.Food:getChildren() -- local clone = foood[math.random(1,#foood)]:Clone() local e = plr.Character.HumanoidRootPart.Position local ab = Vector3.new(e.x, e.y, e.z) for i,v in pairs(e) do game.Workspace.Sponsor.Position = v end end end end
I'm currently trying to move the part's position to the plr's HumanoidRootPart, but I just don't know how to. I previously tried using another for loop by doing that:
for i = 1, ab, .5 do game.Workspace.Sponsor.Position = game.Workspace.Sponsor.Position + i end
I however replaced it with the i,v in pairs thing because it stated ab should be a number, or something like that.
While we're at it, do you guys know how I could give a player a tool when the "Sponsor" part touches the HumanoidRootPart?
Thanks
Hey there!
Judging from your comments, I see that you don't want to set a position, but you want to do what is commonly referred to as "tweening".
There is this cool thing called TweenService, and it makes life a lot easier.
Let me show you how it is done.
local TweenService = game:GetService("TweenService") local sponsorPart = game.Workspace.Sponsor local goal = {} goal.Position = Vector3.new(10,20,30) local tweenInfo = TweenInfo.new(5) -- time it takes for the tween to happen local tween = TweenService:Create(sponsorPart, tweenInfo, goal) tween:Play()
Alternatively, if you wanted to do what you were trying to do before,one easy to understand way to do it would be this:
local OldCFrame = game.Workspace.Sponsor.CFrame for i = 1, ab, .5 do game.Workspace.Sponsor.CFrame = CFrame.new(OldCFrame.X + i,OldCFrame.Y,OldCFrame .Z) end
and you can also do this, but if this confuses you, ignore it.
I know it is a little weird to multiply when you are trying to add, but that is how CFrame works.
for i = 1, ab, .5 do game.Workspace.Sponsor.CFrame = game.Workspace.Sponsor.CFrame*CFrame.new(1,0,0) end
Alright, if I'm not mistaken your part variable is Sponsor; You should use CFrame instead of position:
Sponsor.CFrame = plr.Character.HumanoidRootPart.CFrame -- * CFrame.new(0, 0, 0) can be offset
For the tool: Insert or clone the tool into Sponsor, then add a script / clone a script into sponsor
script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then local tool = script.Parent.TOOL_NAME:Clone tool.Parent = game.Players:FindFirstChild(hit.Parent.Name).Backpack end end)
EDIT:
You should use TewwnService or bodyposition. I don't know much about tween service but I know it has easing. Script for body position:
local bp = Instance.new("BodyPosition", Sponsor) bp.Position = plr.Character.HumanoidRootPart.Position Sponsor.Anchored = false bp.ReachedPosition:connect(function() --Rest of code end)
Edited tool script: script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then if hit.Parent:FindFirstChild("TOOL_NAME") ~= nil and game.Players:FindFirstChild(hit.Parent.Name):FindFirstChild("Tool_") ~= nil then local tool = script.Parent.TOOL_NAME:Clone tool.Parent = game.Players:FindFirstChild(hit.Parent.Name).Backpack end end end)