I want the character to be set at the center of the block it is currently touching
The player is only teleported to which ever it touched first not the one it is currently touching.
Server Script
local ReplicatedService = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local ServerStorage = game:GetService("ServerStorage")
local FixEvent = ReplicatedService:FindFirstChild("Fix")
local function GameRunning(hitbox, part)
hitbox.Touched:Connect(function(hit)
if hit.Name == "LowerTorso" and hit.Parent:FindFirstChildOfClass("Humanoid") then
local player = Players:GetPlayerFromCharacter(hit.Parent)
FixEvent:FireClient(player, hitbox, "Started")
end
end)
hitbox.TouchEnded:Connect(function(hit)
if hit.Name == "LowerTorso" and hit.Parent:FindFirstChildOfClass("Humanoid") then
local player = Players:GetPlayerFromCharacter(hit.Parent)
FixEvent:FireClient(player, hitbox, "Ended")
end
end)
end
local function StartGame(map)
local objects = CollectionService:GetTagged("Generator")
local hitboxes = CollectionService:GetTagged("HitBox")
for i, b in ipairs(objects) do
if b:HasTag(map) then
b:AddTag("InGame")
end
end
for i, b in ipairs(hitboxes) do
if b:HasTag(map) then
b:AddTag("InGame")
GameRunning(b, b.Parent)
end
end
end
Local Script
local ReplicatedService = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local FixEvent = ReplicatedService:FindFirstChild("Fix")
local player = game.Players.LocalPlayer
local visible = false
local function Touched(hitbox)
local function Check(input)
if input.KeyCode == Enum.KeyCode.E and visible == true then
player.Character.LowerTorso.CFrame = hitbox.place.CFrame
print(hitbox.Name)
return
else
return
end
end
UserInputService.InputBegan:Connect(Check)
end
local function Event(hitbox, state)
if state == "Started" then
player.PlayerGui.ScreenGui.Fix.Visible = true
visible = true
Touched(hitbox)
else
player.PlayerGui.ScreenGui.Fix.Visible = false
visible = false
return
end
end
FixEvent.OnClientEvent:Connect(Event)