So I want a part that when you touch it, the FOV changes, but only for that player. I made this basic script to test the function, and I can’t get it to work.
Here is the sever script:
local db = false
local FOV = game.ReplicatedStorage.FOV
script.Parent.Touched:Connect(function(hit, player)
local hitT = hit.Parent:GetChildren()
for i,v in pairs(hitT) do
if v:IsA("Humanoid") then
if not db then
db = true
v.WalkSpeed = 32
FOV:FireClient(player)
script.Parent:Destroy()
wait(5)
v.WalkSpeed = 16
db = false
end
end
end
end)
Whenever I touch it, I get an error:
FireClient: player argument must be a player object
I don’t know why this is happening, is there a way to get player using hit, then use that for the player there?
There’s only the hit parameter, you can’t add another parameter inside the Touched
event
However, you can get the Player by getting the Player’s Character using the GetPlayerFromCharacter
function like so:
local db = false
local FOV = game.ReplicatedStorage.FOV
script.Parent.Touched:Connect(function(hit)
local Character = hit.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
if Player and not db then
db = true
Character.Humanoid.WalkSpeed = 32
FOV:FireClient(Player)
wait(5)
db = false
Character.Humanoid.WalkSpeed = 16
end
end)
hit.Parent
would be referring to the Player’s Character Model in this Instance, and we can check if it’s a valid player or not & if the debounce is still equal to false
2 Likes
Thank you, I recently added the player parameter just to test, and I went with it. Thank you, now I just need to tween it and add sounds! (I can tween it btw)
1 Like