Script only works correctly for one player

You can write your topic however you want, but you need to answer these questions:

  1. I’ve been working on this project for a while, and this bug has been halting my progress. The bug is that a script, Local Script, and script, won’t work for other players. The mechanic is, that you click to kill, but when you press ‘E’, you cant be killed and become blind (becoming blind is fine). It’s hard for me to explain so here is a video.

Video: https://youtu.be/b-BSQP8I6_c

  1. **No solutions :confused: **

Code

Raycast / LocalScript:

-- RayCast Script

local uis = game:GetService("UserInputService")
local rs = game:GetService("RunService")
local camera = workspace.CurrentCamera
local item = nil

local RS = game:GetService("ReplicatedStorage")




local function CreateRayCast()
	local mousePosition = uis:GetMouseLocation()
	local raycast = camera:ViewportPointToRay(mousePosition.x, mousePosition.y)
	local rcResult = workspace:Raycast(raycast.Origin,raycast.Direction * 10000 )
	return rcResult
end

uis.InputBegan:Connect(function(input, proc)
	if input.UserInputType == Enum.UserInputType.MouseButton1 and not proc then
		if item:IsA("BasePart") then
						
			if  item.name == "HumanoidRootPart" or item.name == "Torso" then
			
					
					local RaycastPlayer = game.Players:GetPlayerFromCharacter(item.Parent)


					game.ReplicatedStorage:WaitForChild("KillPlayer"):FireServer(RaycastPlayer) 
				
				
					print(RaycastPlayer.Name .. " Local")
				end
		end
	end
end)

rs.RenderStepped:Connect(function()
	local result = CreateRayCast()

	if result and result.Instance then

		item = result.Instance
	end

end)


EToBlind Script:

-- E to blind script


local db = false

local dbTimer = 1

local WalkSpeedWhileBlind = 5


game.UserInputService.InputBegan:Connect(function(inp, proc)
	if proc == true then return end
	if db == true then return end
	db = true
	
	if inp.KeyCode == Enum.KeyCode.E then
		print("press e")
		
		
		-------------
		game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = WalkSpeedWhileBlind
		
		-------------
		
		game.ReplicatedStorage:WaitForChild("EToBlind"):FireServer()
		
		
	end
	
	task.wait(dbTimer)
		
	db = false
	
	game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = 16
	
	
	
end)

Kill Script:

local RS = game:GetService("ReplicatedStorage")


game.ReplicatedStorage:WaitForChild("KillPlayer").OnServerEvent:Connect(function(player, RaycastPlayer)
	
	local isBool

	
	local children = RaycastPlayer:GetChildren()
	
	for i = 1, #children do
		local child = children[i]
		
		if child:IsA("BoolValue") then
			
			isBool = child
			
		end
		
	end
	
	print(isBool.Value)
	
	if player and isBool.Value == false then
		RaycastPlayer.Character.Humanoid:TakeDamage(100)
		print(isBool.Value)
		print(RaycastPlayer.Name .. " Server")
	else
		print("no kill")
	end
	
	isBool = nil
	
end)

If you would like any more code or more pictures / videos, please feel free to ask!

Where is the EToBlind event code?

I am not sure what you mean, are you asking about the local script? EToBlind is the local script, if that helps.

This? need to get over the character limit

My bad.

local BlindFrame = game.StarterGui.Blind:WaitForChild("Frame")





game.ReplicatedStorage:WaitForChild("EToBlind").OnServerEvent:Connect(function(player)
	
	local BlindFrame = player.PlayerGui.Blind.Frame
	
	local BlindTip = player.PlayerGui.Blind.BlindTip
	
	local BlindSound = player.PlayerGui.Blind["Light Switch ON"]
	
	
	BlindSound:Play()	
	
	
	for i = 1,0, -0.2 do
		
		wait(0.001)
		BlindFrame.BackgroundTransparency = i
		BlindTip.TextTransparency = i

	end
	BlindFrame.BackgroundTransparency = 0
	BlindTip.TextTransparency = 0
	
	task.wait(3)
	
	BlindSound:Play()
	
	for i = 0,1, 0.2 do

		wait(0.001)
		BlindFrame.BackgroundTransparency = i
		BlindTip.TextTransparency = i

	end
	BlindFrame.BackgroundTransparency = 1
	BlindTip.TextTransparency = 1

end)

Can you send the server output when you do what you did in the video so I can try and better understand the problem.

Video with the server output:

Right thanks for the server output. Could you explain what the for loop on the kill script is checking for. I understand its a bool value, but what exactly is this bool value used for?

I copied the section of interest below.

for i = 1, #children do
		local child = children[i]
		
		if child:IsA("BoolValue") then
			
			isBool = child
			
		end
		
	end

The bool is used for checking if the player can be killed or not. Here is the script for instancing the bool into the player:

bool = nil


game.Players.PlayerAdded:Connect(function(p)
	bool = Instance.new("BoolValue")
	bool.Name = p.Name .. "Blindness"
	bool.Parent = p
end)

game.ReplicatedStorage:WaitForChild("EToBlind").OnServerEvent:Connect(function(player)
	
	bool.Value = true
	
	wait(5)
	
	bool.Value = false
	
end)

If you have any better way for doing this, feel free to change or tell me.

Where are you getting playerBool from and what is _name?

Ah sorry my bad a small formatting error, there should be no space. Basically playerBool_name is the name of the variable that holds the name of the bool for example in the code above you have have set the boolean name to bool.Name = p.Name .. "Blindness", therefore I also set a variable to get the player.name and add “Blindness” to it. so that it can be found and referenced inside the individual player.

In fact the code I previously provided might contain an error. Below I have pasted an improvement that should work.

bool = nil


game.Players.PlayerAdded:Connect(function(p)
	bool = Instance.new("BoolValue")
	bool.Name = "Blindness"
	bool.Parent = p
end)

game.ReplicatedStorage:WaitForChild("EToBlind").OnServerEvent:Connect(function(player)
	
	player.Blindness.Value = true
	
	wait(5)
	
	player.Blindness.Value = false
	
end)

Since the blindness bool has player as its parent, there is no need to have the player name in the bool, so I simply took out the p.Name part.

This works thanks! And about the bool name, the player name in the bool was used for testing purposes (cant remeber why lol).

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.