Hello
01 | function onClick(noot) |
02 | local val = script.Parent.Parent.TextBox.Value.Value |
03 | local text = script.Parent.Parent.TextBox |
04 | val = text.Text |
05 | local plr = game.Players:FindFirstChild(val) |
06 | local val 2 = script.Parent.Parent.dis.Value.Value |
07 | local text 2 = script.Parent.Parent.dis |
08 | val 2 = text 2. Text |
09 | local item = game.ServerStorage.SponsorItems:FindFirstChild(val 2 ) |
10 | if plr and plr.Character and plr.Character:FindFirstChild( "Arm1" ) and item then |
11 | if val 2 = = "Food" then |
12 | local foood = game.ServerStorage.SponsorItems.Food:getChildren() |
13 | -- local clone = foood[math.random(1,#foood)]:Clone() |
14 | local e = plr.Character.HumanoidRootPart.Position |
15 | local ab = Vector 3. new(e.x, e.y, e.z) |
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:
1 | for i = 1 , ab, . 5 do |
2 | game.Workspace.Sponsor.Position = game.Workspace.Sponsor.Position + i |
3 | 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.
01 | local TweenService = game:GetService( "TweenService" ) |
02 |
03 | local sponsorPart = game.Workspace.Sponsor |
04 |
05 | local goal = { } |
06 | goal.Position = Vector 3. new( 10 , 20 , 30 ) |
07 |
08 | local tweenInfo = TweenInfo.new( 5 ) -- time it takes for the tween to happen |
09 |
10 | local tween = TweenService:Create(sponsorPart, tweenInfo, goal) |
11 |
12 | 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:
1 | local OldCFrame = game.Workspace.Sponsor.CFrame |
2 | for i = 1 , ab, . 5 do |
3 | game.Workspace.Sponsor.CFrame = CFrame.new(OldCFrame.X + i,OldCFrame.Y,OldCFrame .Z) |
4 | 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.
1 | for i = 1 , ab, . 5 do |
2 | game.Workspace.Sponsor.CFrame = game.Workspace.Sponsor.CFrame*CFrame.new( 1 , 0 , 0 ) |
3 | end |
Alright, if I'm not mistaken your part variable is Sponsor; You should use CFrame instead of position:
1 | 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
1 | script.Parent.Touched:connect( function (hit) |
2 | if hit.Parent:FindFirstChild( "Humanoid" ) ~ = nil then |
3 | local tool = script.Parent.TOOL_NAME:Clone |
4 | tool.Parent = game.Players:FindFirstChild(hit.Parent.Name).Backpack |
5 | end |
6 | 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:
1 | local bp = Instance.new( "BodyPosition" , Sponsor) |
2 | bp.Position = plr.Character.HumanoidRootPart.Position |
3 | Sponsor.Anchored = false |
4 | bp.ReachedPosition:connect( function () |
5 | --Rest of code |
6 | 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)