I’ve done this but I’m getting the error “attempt to index boolean with ‘Parent’”, referring to “:GetPlayerFromCharacter(hit.Parent)”
Then your hit variable is a boolean and not an object within the Player’s character. Where are you calling this function? What value are you passing into it? I can help if you can’t figure it out but I have to see the code where you are using cammodule.toggleon()
.
SORRY! I see what I did wrong. I had a part in workspace that was activating the module and I put true in there, thinking I’d use toggle as a variable. Basically a dumb mistake.
Anyway, now I’m getting the error “FireClient: player argument must be a Player Object”
this is the script within the part:
script.Parent.Touched:Connect(function(hit)
local cammodule = require(game.ServerScriptService.Modules:FindFirstChild("2DCamera"))
cammodule.toggleon(hit)
end)
with this considered the module should just be able to get the player easily right? I’m not sure what’s up here
It should get the player easily. You could try changing it to this:
local Players = game:GetService("Players")
local cammodule = require(game.ServerScriptService.Modules:FindFirstChild("2DCamera"))
script.Parent.Touched:Connect(function (hit)
if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") ~= nil then
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
cammodule.toggleon(player)
end
end
end)
Get the player from the character and check if the player variable exists inside the Touched event instead of the Module. This will reduce calls to the module. I also checked if the parent is a model and if it has a humanoid.
I’m gonna take the time now to apologise for how tedious this is and how slow I am
Thank you for taking the time trying to fix this
But, with that said, there’s no longer any errors, but I don’t think the camerascript in starterplayer is detecting the event
local cam = workspace.CurrentCamera
local char = script.Parent
local hrp = char:WaitForChild("HumanoidRootPart")
local cas = game:GetService("ContextActionService")
game.ReplicatedStorage["2DCamEvent"].OnClientEvent:Connect(function(toggle)
print("success")
script.toggle.Value = toggle
end)
“Success” wasn’t printed
If I had to guess it’s probably because you aren’t firing the event on the server? Make sure your code inside cammodule.toggleon(hit)
is running.
Haha, it’s all good RemoteEvents are sort of tricky if you don’t really understand how they work or Server-Client interactions. Honestly, just sitting down for a while to learn API documentation on all of it will REALLY help in the long run.
Yeah haha, I have used them before and I know how they work, it’s just been a year or so so I’m a bit out of practice
Anyway, the module script works fine, it prints whatever I put in there so it’s definitely working. The player is also definitely correct, I printed the player’s name and it gave the right one. So I’m not really sure why it isn’t working
I FIXED IT!!!
Thank you so much for the help! At the top of the camera script in playerscripts it still referenced the character via script.Parent. Swapped it out for LocalPlayer and now it works fine
Again thank you for all the advice and putting up with all the errors haha, I’m quite rusty on scripting so tedious bug and error fixing like this should hopefully bring back the scripting mindset for me a bit haha