I have a tool that has local and server scripts inside and Remote event.
when you activate the tool (click while equipped) local script sends a remote event to server with desired information. Server script in tool receives it and It copies the part from replicated storage several times and parents it to works space.
SO the part that is in replicated storage has script inside that is also connected to that remote event. And when i click the tool i want that script to accept that remote and get info. But since it doesnt and i have no clue why i cant make it so that spikes wont damage you. (they should dmg everything besides owner of tool).
local script in tool:
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Event = tool.RemoteEvent
local char = player.Character
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(.01)
local function onActivated()
local MouseHit = mouse.Hit.Position
local MouseHitPosition = Vector3.new(MouseHit.X, char.HumanoidRootPart.Position.Y, MouseHit.Z)
local goal = {}
goal.CFrame = CFrame.new(char.HumanoidRootPart.Position, MouseHitPosition)
local tween = ts:Create(char.HumanoidRootPart, ti, goal)
tween:Play()
--char.HumanoidRootPart.CFrame = CFrame.new(char.HumanoidRootPart.Position, MouseHitPosition)
--Event:FireServer(mouse.Hit.Position)
Event:FireServer(CFrame.new(char.HumanoidRootPart.Position, MouseHitPosition))
end
local function onUnequipped()
--print("tool was unequipped")
end
local function onEquipped()
--print("tool was equipped")
end
tool.Activated:Connect(onActivated)
tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)
server script in tool
local tool = script.Parent
local Players = game:GetService("Players")
local Event = tool.RemoteEvent
local ts = game:GetService("TweenService")
Event.OnServerEvent:Connect(function(player, cframe)
print("1st script accepted event")
local char = player.Character
local spikePos = nil
local Height = 0
for i = 0, 0.7, 0.1 do
if i == 0 then
local part = game.ReplicatedStorage.Ground:Clone()
part.Anchored = true
part.CFrame = cframe * CFrame.new(0, -1.5, -10)
spikePos = part.CFrame
part.CFrame = cframe * CFrame.new(0, -5, -10)
Height = part.Size.Y
part.Parent = game.Workspace
local goal = {}
goal.CFrame = spikePos
local ti = TweenInfo.new(1-i)
local tween = ts:Create(part, ti, goal)
tween:Play()
task.wait(i)
--tween.Completed:Wait()
else
Height += 2
local part = game.ReplicatedStorage.Ground:Clone()
part.Size = Vector3.new(part.Size.X, Height, part.Size.Z)
part.Anchored = true
part.CFrame = spikePos * CFrame.new(0, 1, -5)
spikePos = part.CFrame --* CFrame.new(0, 1, 0)
part.CFrame = spikePos * CFrame.new(0, -1.5-Height, 0)
part.Parent = game.Workspace
local goal = {}
goal.CFrame = spikePos
local ti = TweenInfo.new(1-i)
local tween = ts:Create(part, ti, goal)
tween:Play()
task.wait(i)
--tween.Completed:Wait()
end
end
--[[local part = game.ReplicatedStorage.Ground:Clone()
part.Anchored = true
part.CFrame = cframe * CFrame.new(0, 0, -20)
part.Parent = game.Workspace]]
end)
server script in part that is in replicated storage:
local part = script.Parent
local flag = true
local char = nil
local player = nil
local humanoid = nil
local tool = game.Workspace.SpikesTweenOwner
local remote = tool.RemoteEvent
local owner = nil
remote.OnServerEvent:Connect(function(plr)
print("second accepted")
owner = plr
print(owner)
end)
part.Touched:Connect(function(hit)
char = hit.Parent
humanoid = char:FindFirstChild("Humanoid")
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player == owner then
return
else
if flag == true and humanoid then
flag = false
humanoid.Health = humanoid.Health - 33
end
end
end)
I would be extremely grateful to a soul that could explain me what is the problem! Any advice is appreciated