I’m trying to make a summoning script to summon the specified player infront of me, but it’s not working.
Local script: (startercharacterscripts)
wait(2)
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Mouse = Player:GetMouse()
local UserInputService = game:GetService("UserInputService")
repeat
wait()
until Character.Parent == workspace
local Debounce = false
Player.Chatted:Connect(function(Message)
local lower = string.lower(Message)
local Object = nil
local targetPlayer = nil
if string.sub(lower, 1, 9) == "i summon, " and not Debounce then
Debounce = true
local Target = string.sub(lower, 10, #lower)
for _,v in next, Players:GetPlayers() do
if string.sub(string.lower(v.Name), 1, #Target) == Target then
Object = v.Character.Humanoid
targetPlayer = v
end
end
if not Object then
for _,v in next, workspace:GetDescendants() do
if v.Name:lower() == Target and v:IsA("Model") then
Object = v
end
end
end
if targetPlayer then
game.ReplicatedStorage.AbilityEvents.Summon:FireServer(targetPlayer)
wait(5)
Debounce = false
return
end
end
end)
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Mouse = Player:GetMouse()
local UserInputService = game:GetService("UserInputService")
repeat
wait()
until Character.Parent == workspace
local Debounce = false
Player.Chatted:Connect(function(Message)
print("yes0")
local lower = string.lower(Message)
local Object = nil
local targetPlayer = nil
print(string.sub(lower, 1, 9))
if string.sub(lower, 1, 9) == "i summon," and not Debounce then
print("yes1")
Debounce = true
local Target = string.sub(lower, 11, #lower)
print(Target)
for _,v in next, Players:GetPlayers() do
if string.sub(string.lower(v.Name), 1, #Target) == Target then
Object = v.Character.Humanoid
targetPlayer = v
end
end
if not Object then
for _,v in next, workspace:GetDescendants() do
if v.Name:lower() == Target and v:IsA("Model") then
Object = v
end
end
end
if targetPlayer then
print("yes2")
game.ReplicatedStorage.AbilityEvents.Summon:FireServer(Player.Name,targetPlayer.Name)
wait(5)
Debounce = false
return
end
end
end)
i tried this and it worked, the problem was with the space in the if statement and then i changed line 23 from 10 to 11. and some adjustments in server script but that was with the remote event., delete the yes0 and the rest, that was just to see if the if statements fired