When I was working on my game, I decided I would have a block that gives the player an item and teleports them to a certain place. For some reason, however, the item giver isn't working. I made the script a local script.
01 | local teleblox = game.Workspace.BloxxerStatueModel.TheBStatue.Teleporter |
02 | local Fight = game.ServerStorage.Fight |
03 | local FightClone = Fight:Clone() |
04 |
05 | local function pint() |
06 | FightClone.Parent = game.Players.LocalPlayer.Backpack |
07 | print ( "oml it worked" ) |
08 | end |
09 |
10 | script.Parent:findFirstChild( "Humanoid" )(pint) |
You need an event that will detect when the player is touching the block. In this case, Touched should do.
01 | local teleblox = game.Workspace.BloxxerStatueModel.TheBStatue.Teleporter |
02 | local Fight = game.ServerStorage.Fight |
03 | local FightClone = Fight:Clone() |
04 |
05 |
06 |
07 | script.Parent.Touched:Connect( function (hit) |
08 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
09 | FightClone.Parent = game.Players.LocalPlayer.Backpack |
10 |
11 | print ( "oml it worked" ) |
12 |
13 | end |
14 | end ) |
Assuming that you are placing the script within whatever block you need to touch.
Assuming you want to use a touch event, here is what I made.
01 | local teleblox = game.Workspace:WaitForChild( 'Teleporter' ) |
02 | local Fight = game.ReplicatedStorage:WaitForChild( 'Fight' ) |
03 | local tp = - 23.36 , 0.5 , 26.03 |
04 | debounce = 0 |
05 | function pint(hit) |
06 | if debounce = = 0 then |
07 | debounce = 1 |
08 | if hit.Parent:FindFirstChild( 'Humanoid' ) ~ = nil then |
09 | local pn = hit.Parent.Name |
10 | local p = game.Players:FindFirstChild(pn) |
11 | local FightClone = Fight:Clone() |
12 | FightClone.Parent = p.Backpack |
13 | hit.Parent:FindFirstChild( 'HumanoidRootPart' ).Position = Vector 3. new(- 23.36 , 0.5 , 26.03 ) |
14 | print ( "ommeeee gaaawdd it worked" ) |
15 | wait( 1 ) |
16 | debounce = 0 |
17 | end |
18 | end |
19 | end |
20 | script.Parent.Touched:Connect(pint) |
p.s - sorry it took so long