Hi, I am making this survival game, where a random player gets picked to become the murderer to kill survivors, in order to do this, I have to give certain scripts and functions to the player but I do not really know how.
Sometimes when I code in Roblox Lua, I have no idea what I am doing.
Here’s what I have so far:
local players = game:GetService("Players"):GetPlayers()
local picked = players[math.random(1, #players)]
There seems to be more details left out. Do you have any scripts that discerns and separate between what makes a player the murderer? What do you expect to happen?
Those options are close to my goal, yes the abilities are only on the selected player’s client.
for instance: if the player presses “F”, An attack animation plays with it’s hitbox like:
local players = game:GetService("Players"):GetPlayers()
local picked = players[math.random(1, #players)]
local pickedchar = picked.Character or picked.CharacterAdded:Wait()
local Humanoid = pickedchar.Parent:FindFirstChild("Humanoid")
local key = game:GetService("UserInputService")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://10544400098"
key.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
local animationTrack = Humanoid:LoadAnimation(animation)
animationTrack:Play()
-- attack code
end
end)
Of course, I want to do this only on the selected player.
The client can detect a change theirself and run a function, or the server can specifically tell the client to run this function. So the remote event would tell every player what their role is, and the client would tell the player.
local Frame = script.Parent.OxFrame
local Bar = Frame.OxBar
local Lable = Frame.OxLabel
local Player
local Stoping = false
game.Workspace.O2Lose.Touched:Connect(function(hit)
Player = game.Players.LocalPlayer
if hit and hit.Parent:FindFirstChild("Humanoid") then
if Player.Name == hit.Parent.Name then
if Stoping then
return
end
Stoping = true
for i = 442 , -55 , -5 do
Bar.Size = UDim2.new(0, i,0, 35)
Lable.Text -= 1
wait(0.01)
end
if Lable.Text == "0" then
while wait(0.5) do
Player.Character.Humanoid:TakeDamage(10)
end
end
end
end
end)
You really only need to check the player name with whoever touched the part.
Since the abilities are given by connecting the ability function to the user input, you can get the server to fire a RemoteEvent to the chosen player, and in a local script you can code it so that, if that RemoteEvent is fired for this player, bind all the special abilities
example code, in a local script (given to every player)
local remote = game.ReplicatedStorage:WaitForChild('RemoteEvent') -- name the remote whatever
remote.OnClientEvent:Connect(function()
key.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
local animationTrack = Humanoid:LoadAnimation(animation)
animationTrack:Play()
-- attack code
end
end)
end)