Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to pass the player value in a bindable event?

Asked by 5 years ago
Edited 5 years ago

touched script

script.Parent.Touched:Connect(function()
    local Players = game.Players
    local part = script.Parent
    local player = Players:GetPlayerFromCharacter(part.Parent)
    game.ReplicatedStorage:WaitForChild("PurchaseZone"):Fire(player,script.Parent.Name,10)
end)

I am working on a game, i am trying to pass the player who touched a certain brick to another script but it returns a nil value, i tried getplayerfromcharacter but no success, any other methods?

receiver

game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = Player
    local zones = Instance.new('Folder')
    zones.Name = "Zones"
    zones.Parent = Player
    local candy = Instance.new("IntValue")
    candy.Name = "Candy"
    candy.Parent = leaderstats 
    candy.Value = 10
    local currenttool = Instance.new("Folder")
    currenttool.Name = "CurrentTool"
    currenttool.Parent =Player
    local testzone = Instance.new("StringValue")
    testzone.Name = "Partt"
    testzone.Value = "Partt"
    testzone.Parent = zones
end)

game.ReplicatedStorage.PurchaseZone.Event:Connect(function(player,zone,cost)
if player.Zones:GetChildren().Name ~= zone and player.leaderstats.Candy.Value >= cost then
        local zoneadded = Instance.new("StringValue")
        zoneadded.Parent = player.Zones
        zoneadded.Name = zone
        zoneadded.Value = zone
     end
end)
0
how are you passing it? and it would probably be beneficial to see some code Vulkarin 581 — 5y
0
edit the question put both scripts in a code block Vulkarin 581 — 5y
0
done BitStreams 4 — 5y
0
closer, but it's not a code block..play around with the buttons until you see code block and then paste it into that Vulkarin 581 — 5y
View all comments (2 more)
0
there you go, sorry, new to this website BitStreams 4 — 5y
0
No worries Vulkarin 581 — 5y

1 answer

Log in to vote
1
Answered by
Vulkarin 581 Moderation Voter
5 years ago
Edited 5 years ago

I've made some changes, you are trying to get the character from script.Parent but instead you should be using the parent of the touching part itself given from the Touched event

script.Parent.Touched:Connect(function(part) 
    local Players = game.Players 
    local player = Players:GetPlayerFromCharacter(part.Parent)
    if player then
        game.ReplicatedStorage:WaitForChild("PurchaseZone"):Fire(player,script.Parent.Name,10) 
    end
end)
1
i did try the If player part, ill try this now thanks! BitStreams 4 — 5y
0
if player will prevent it from sending a nil value Vulkarin 581 — 5y
1
Yeah, when i tried if player with my code it did nothing obviously, this worked thanks! BitStreams 4 — 5y
Ad

Answer this question