I need some help with a script.
I have tried to look for it on internet, but cant find anything about it.
Im not a scripter. Im just a mom thats making a game with my kids
I would like some help with this:
I need a script that makes one teams player touch the other teams player they die.
like this: team Police touch team Thief. Team Thief die. Nothing happens to team Police.
I have been thinking about using some kind of touch function. but since im not a scripter i cant really make it⌠thank you for helping me <3
A friend made this for me. but it doesnt work:
local Players = game:GetService(âPlayersâ)
local function onCharacterAdded(character)
local player = Players:GetPlayerFromCharacter(character)
if player and player.Team then
local humanoid = character:WaitForChild(âHumanoidâ)
local function onTouch(other)
local otherCharacter = other.Parent
local otherPlayer = Players:GetPlayerFromCharacter(otherCharacter)
if otherPlayer and otherPlayer.Team then
-- Check if the player is on the Red team and the toucher is on the Blue team
if player.Team.Name == "Red" and otherPlayer.Team.Name == "Blue" then
-- Kill the Red team player
humanoid.Health = 0
end
end
end
character.Touched:Connect(onTouch)
end
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
i have also tried this that another friend made. doesnt work either
â Get the teams
local team1 = game.Teams.Team1
local team2 = game.Teams.Team2
â Function to kill player if touched by other team
local function onTouch(hit)
â Check if the player is on team1 and the hitter is on team2
if hit.Parent:FindFirstChild(âHumanoidâ) and hit.Parent.Parent == team1 and game.Players:GetPlayerFromCharacter(hit.Parent) and game.Players:GetPlayerFromCharacter(script.Parent).Team == team2 then
â Kill the player
hit.Parent.Humanoid:TakeDamage(100)
end
end
â Connect the onTouch function to the Touched event of the playerâs character
game.Players.PlayerAdded:Connect(function(player)
if player.Team == team1 then
player.CharacterAdded:Connect(function(character)
character:WaitForChild(âHumanoidRootPartâ).Touched:Connect(onTouch)
end)
end
end)
maybe something that they use in hide and seek games?!
can i use something like this???
seeker.Character.HumanoidRootPart.Anchored = false
for i, part in pairs(seeker.Character:GetChildren()) do
if part:IsA("MeshPart") or part:IsA("BasePart") then
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player and not player:FindFirstChild("IsSeeker").Value then
hit.Parent:SetPrimaryPartCFrame(workspace.SpawnLocation.CFrame)
player.Character.HumanoidRootPart.Anchored = true
for i, v in pairs(GamePlayers) do
if v == player then
table.remove(GamePlayers, i)
break
end
end
end
end
end)
end
end
Hello! At a quick glance, I think the original code your friend gave you should work as long as your teams are âRedâ and âBlueâ.
However, I did notice something. When I copied and pasted your code into my Roblox Studio, the âPlayersâ and âHumanoidâ in quotation marks were red underlined, so you might have used quotation symbols that donât work. A bit of a strange solution, but maybe try using this code again, but replacing those words using copy and paste "Players"
"Humanoid"
and make sure to replace the old quotation marks with the new ones.
Let me know if it works?
should i put it as a localscript in StarterPlayerScripts?
It should be a server script (Itâs grey and called âScriptâ) and put it in ServerScriptService.
sorry it still doesnt work⌠not sure whats wrong
I have written some code that should help with your problem.
The first section of code below should be put into a localscript and placed into StarterCharacterScripts
local players = game:GetService("Players")
local deadEvent = game:GetService("ReplicatedStorage"):WaitForChild("DeadEvent")
local localplayer = players.LocalPlayer
local char = localplayer.Character or localplayer:WaitForChild("Character")
char.Humanoid.Touched:Connect(function(otherpart)
if otherpart.Parent:FindFirstChild("Humanoid") and localplayer.Team.Name == "Police" then
local otherplayer = players:GetPlayerFromCharacter(otherpart.Parent)
if otherplayer.Team.Name == "Theif" then
deadEvent:FireServer(otherplayer)
end
end
end)
You will also need to make a RemoteEvent named DeadEvent
in order to handle the other players.
After that you will need to put the below code in script in ServerScriptStorage
The code iâm placing below is the remote event that signals that the robber should die.
local deadEvent = game:GetService("ReplicatedStorage"):WaitForChild("DeadEvent")
deadEvent.OnServerEvent:Connect(function(player, otherplayer)
local otherchar = otherplayer.Character or otherplayer:WaitForChild("Character")
otherchar.Humanoid:TakeDamage(100)
end)
Try this and see if it works, if you have any problems let me know.
sorry but that doesnt work eitherâŚ
Thatâs alright. If you go to the View tab and open up the Output box, then you can see if thereâs any errors. If there are errors, you can click it and itâll take you to where the problem is. Can you share if thereâs anything in the output when you run the game?
no errors either⌠i really have no idea what to do
Are there any errors in the output tab?
i have to publish every time i want to try it out⌠haha
Can you run the game in studio? Go to the test tab and click âPlayâ. Then send us what the output looks like whilst itâs playing?
i cant. i have a error when i try that
No need to, if you want to try your game out with more than one player to test it you can click on the Test tab at the top of studio and the Start Icon, making sure that you have selected more than 1 player.
how do i select more than 1 player?